2012-10-05 128 views
0

我是非常新的C#。我想創建一個小控制檯應用程序,設置了以下內容:清除該信息,並設置"Obtain an IP address automatically""Obtain DNS server address automatically"更改IP地址,子網掩碼,dns服務器和默認網關在C#

IP address: 192.168.10.133 
Subnet mask: 255.255.255.0 
Default gateway: 192.168.10.66 
Preferred DNS server: 192.168.10.3 
Alternate DNS server: 192.168.10.5 

和另一個小應用程序。

我發現了一些人們在本論壇和其他論壇發佈的腳本示例,但我無法讓它們工作。

這可能有很多要問,但我會很感激,如果有人可以發佈一些東西,這將幫助我。

我真的很感激它!

+2

你有什麼了嗎? – oberfreak

回答

0

我已經決定去與該另一條路線。我只是想通過批處理文件來設置它,而不是使用C#。

set_static_ip.bat

netsh interface ip set address name="Local Area Connection" static 192.168.0.10 255.255.255.0 192.168.0.1 
netsh interface ip set dnsservers "Local Area Connection" static 192.168.0.3 primary 

第一行設置的IP地址和默認網關。 第二行設置主DNS服務器。我一直無法設置備用DNS,但我確信我只是錯過了一些東西。

如果您想要更改配置以自動獲取IP地址,那麼您只需運行下面的代碼即可。

set_auto_ip.bat

netsh interface ip set address name="Local Area Connection" source="dhcp" 
netsh interface ip set dnsservers name="Local Area Connection" source=dhcp 

簡單而有效的。

-4

更改TCP/IP設置

TCP/IP定義了您的計算機與其他計算機進行通信的語言。如果您的網絡支持,我們建議使用自動動態主機配置協議(DHCP)爲網絡上的計算機自動分配Internet協議(IP)地址。如果您使用DHCP,則在將計算機移到其他位置時不必更改設置,並且DHCP不要求您手動配置域名系統(DNS)和Windows Internet名稱服務(WINS)等設置)。

1.

Open Network Connections by clicking the Start button Picture of the Start button, clicking Control Panel, clicking Network and Internet, clicking Network and Sharing Center, and then clicking Manage network connections. 

2.

Right-click the connection that you want to change, and then click Properties. Administrator permission required If you are prompted for an administrator password or confirmation, type the password or provide confirmation. 

3.

Click the Networking tab. Under This connection uses the following items, click either Internet Protocol Version 4 (TCP/IPv4) or Internet Protocol Version 6 (TCP/IPv6), and then click Properties. 

4.

To specify IPv4 IP address settings, do one of the following: 
     * 

     To obtain IP settings automatically, click Obtain an IP address automatically, and then click OK. 
     * 

     To specify an IP address, click Use the following IP address, and then, in the IP address, Subnet mask, and Default gateway boxes, type the IP address settings. 

5.

To specify IPv6 IP address settings, do one of the following: 
     * 

     To obtain IP settings automatically, click Obtain an IPv6 address automatically, and then click OK. 
     * 

     To specify an IP address, click Use the following IPv6 address, and then, in the IPv6 address, Subnet prefix length, and Default gateway boxes, type the IP address settings. 

6.

To specify DNS server address settings, do one of the following: 
     * 

     To obtain a DNS server address automatically, click Obtain DNS server address automatically, and then click OK. 
     * 

     To specify a DNS server address, click Use the following DNS server addresses, and then, in the Preferred DNS server and Alternate DNS server boxes, type the addresses of the primary and secondary DNS servers. 
To change DNS, WINS, and IP settings, click Advanced. 
0

只是添加一個額外的點narfie的非常有用的職位(14年9月12日在13:01)。

如果你想與主之一沿着設置備用DNS地址,使用以下命令:

netsh接口IP地址名稱=「本地連接」靜態192.168.0.10 255.255.255.0 192.168。 0.1

netsh接口IP dnsservers 「本地連接」 靜態192.168.0.3初級

netsh接口的IPv4添加DNS名稱= 「本地連接」 196.14.239.2

相關問題