PDA

Click to See Complete Forum and Search --> : Changing Ip adress, gateway & subnet mask of a connection


makem73
Mar 12th, 2006, 10:25 AM
:confused:

Hi i'm trying to make a tool that can change a connections Ip address, gateway address and subnet mask. This is instead of going into Network connections -> Lan properties -> Internet protocol properties in windows. I know i can find the address using winsock. But how do i change it ?? Any suggestions , tips or tricks??

Thanks

mpdeglau
Mar 16th, 2006, 04:08 PM
You can change it using WMI classes. Take a look at this class. I believe most of what you want to do is taken care of here.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_wmi.asp

sevenhalo
Mar 16th, 2006, 04:10 PM
Welcome to VBF :wave:

netsh is a great commandline tool.

Just open a console and type "netsh"

Using "?" on each command should help you through it.

Although, for chnging this stuff programatically, WMI is a better way to go if you can make it work (it will be alot cleaner).

rory
Dec 22nd, 2006, 04:16 AM
this is an old post, but here is the WMI for changing to Static ..
Includes IP, Subnet, Gateway, and DNS. Just leave out the DNS if you dont need it.


Sub Set_Static()
Dim objWMIService, colNetAdapters, objNetAdapter
Dim strIPAddress, strSubnetMask, strGateway, strGatewaymetric, strDNS
Dim errEnable, errGateways, errDNS
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration " _
& "where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.101")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.1")
strGatewaymetric = Array(1)
strDNS = Array("10.10.10.10", "10.10.10.11")
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
Next
End Sub