VisualBasic輔導(dǎo):vb實(shí)現(xiàn)IP設(shè)置

字號(hào):

以假亂真 Linux中實(shí)現(xiàn)Vista界面Max粒子系統(tǒng)輕松實(shí)現(xiàn)群蝶飛舞,利用VB6.0實(shí)現(xiàn)五線譜作曲工具,ASP.NET系統(tǒng)用戶權(quán)限設(shè)計(jì)與實(shí)現(xiàn),用vb實(shí)現(xiàn)ftp的上傳下載Java運(yùn)行時(shí)多態(tài)性的實(shí)現(xiàn),C#委托的具體實(shí)現(xiàn)方法,輕松實(shí)現(xiàn)電腦一分為二:Betwin讓Excel 2007實(shí)現(xiàn)雙面打印的兩種另盜QQ的密碼軟件模擬實(shí)現(xiàn)(VC)
    其實(shí)利用vb修改ip地址是比較容易的。我利用的就是wmi方式。先是找出當(dāng)前系統(tǒng)的所有網(wǎng)卡信息,下面給出的是找出所有網(wǎng)卡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 ’找第一個(gè)網(wǎng)卡就退出
    Next obj End Function
    然后根據(jù)所找到的各個(gè)網(wǎng)卡的進(jìn)行信息(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 ’只修改第一個(gè)網(wǎng)卡的設(shè)置
    End If Next End Function