vb简单的IP设置转换器

  这些天总是带着笔记本在家/单位/客户等等几个地方跑来跑去的,于是在各个地方上网都是要重新设置的,有时候有线,有时候无线。唉,昨天我终于爆发了,再也受不了这么没有尽头的折磨了。于是我又用vb写了一个简单的IP设置转换器。(我已经上传,地址:http://download.csdn.net/source/500624)
界面如下:


其实利用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