I am VERY new to C#. I want to create a small console app that sets the following:
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
and another small app that clears that information and sets "Obtain an IP address automatically"
and "Obtain DNS server address automatically"
.
I've found some examples of scripts that people have posted on this forum and other forums, but I can't get them to work.
It might be a lot to ask, but I would appreciate if someone could post something here that will help me.
I really appreciate it!
I have decided to go another route with this. Instead of using C#, I'm simply going to set it via a batch file.
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
The first line sets the ip and default gateway. The second line sets the primary dns server. I haven't been able to set the alternate dns, but i'm sure i'm just missing something.
If you want to change the configuration back to obtain an ip address automatically, then you simply run the code below.
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
Simple yet effective.