分类:
2008-10-15 13:52:57
界面如下:
其实利用vb修改ip地址是比较容易的。我利用的就是wmi方式。先是找出当前系统的所有网卡信息,下面给出的是找出所有网卡MAC地址的例程: Function GetMACaddress() Dim tempBool As Boolean strComputer = "." Set objWMIServiceGL = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colNetAdaptersGL = objWMIServiceGL.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where(IPEnabled=TRUE)")
For Each obj In objs getMACAddress = getMACAddress & obj.macaddress & vbCrLf & vbCrLf 'Exit For '找第一个网卡就退出 Next obj End Function
然后根据所找到的各个网卡的进行信息(IP,DNS等)更改:
Function ModifyIP() strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" & Combo1.Text & "'") For Each objNetAdapter In colNetAdapters sip = objNetAdapter.IPaddress(0) If Option1.Value = True Then 'DHCP is enabled objNetAdapter.EnableDHCP errDNS = objNetAdapter.SetDNSServerSearchOrder() Else strIPAddress = Array(Text1.Text) strSubnetMask = Array(Text2.Text) strGateway = Array(Text3.Text) strGatewaymetric = Array(1) StrDns = Array(Text4.Text, Text5.Text) errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) errDNS = objNetAdapter.SetDNSServerSearchOrder(StrDns) 'Exit For '只修改第一个网卡的设置 End If Next End Function