如何修改預設閘道器及DNS

2021-04-18 08:40:55 字數 4068 閱讀 5073

function changeip(byval ip as string, byval nm as string, byval gw as string, byval mdns as string, byval sdns as string) as string

'返回值說明:返回乙個設定的中文說明.

dim strcomputer, objwmiservice, colnetadapters, stripaddress, strsubnetmask

dim strgateway, strgatewaymetric, strdns, objnetadapter, errenable, errgateways, errdns

strcomputer = "."

objwmiservice = getobject("winmgmts://" & strcomputer & "/root/cimv2")

colnetadapters = objwmiservice.execquery("select * from win32_networkadapterconfiguration where ipenabled=true")

stripaddress = array(ip) 'ip位址

strsubnetmask = array(nm) '子網掩碼

strgateway = array(gw) '閘道器

strdns = array(mdns, sdns) '主dns各備dns

strgatewaymetric = array(1)

for each objnetadapter in colnetadapters

errenable = objnetadapter.enablestatic(stripaddress, strsubnetmask)

errgateways = objnetadapter.setgateways(strgateway, strgatewaymetric)

errdns = objnetadapter.setdnsserversearchorder(strdns)

if errenable = 0 and errgateways = 0 and errdns = 0 then

changeip = "設定成功"

else

if errenable = 0 then

changeip = "ip位址和子網掩碼設定成功, "

else

changeip = "ip位址或子網掩碼設定失敗, "

end if

if errgateways = 0 then

changeip = changeip & "預設閘道器設定成功, "

else

changeip = changeip & "預設閘道器設定失敗, "

end if

if errdns = 0 then

changeip = changeip & "dns設定成功"

else

changeip = changeip & "dns設定失敗"

end if

end if

next

end function

private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click

msgbox(changeip("192.168.1.12", "255.255.255.0", "192.168.1.1", "201.96.112.133", "84.124.96.122"))

end sub

private function ipcheng(byval name as string, byval ip as string, byval submask as string, byval gateway as string, byval mdns as string, byval sdns as string)

'介面說明name是計算機名字,ip是計算機的ip位址,submask是子網瑪,gateway是閘道器, mdns是主dns,sdns是備用dns

dim objwmiservice, colnetadapters, stripaddress, strsubnetmask

dim objnetadapter, colcomputers, objcomputer

dim errenable as integer

objwmiservice = getobject("winmgmts://./root/cimv2")

colnetadapters = objwmiservice.execquery("select * from win32_networkadapterconfiguration where ipenabled=true")

for each objnetadapter in colnetadapters

errenable = objnetadapter.enablestatic(array(ip), array(submask)) 'ip和子網

doevents()

objnetadapter.setgateways(array(gateway), array(1)) '閘道器

doevents()

objnetadapter.setdnsserversearchorder(array(mdns, sdns)) '可能要設成陣列

next

objwmiservice = getobject("winmgmts:" & "!//./root/cimv2")

colcomputers = objwmiservice.execquery("select * from win32_computersystem")

for each objcomputer in colcomputers

objcomputer.rename(name)

next

end function

private sub cmdset_click()

dim computername as string

if len(trim(txtno.text)) = 1 then

computername = "0" + trim(txtno.text)

else

computername = trim(txtno.text)

end if

if trim(txtno.text) <> "" then

ipcheng("v" + computername, "125.125.125." + txtno.text, "255.255.255.0", "125.125.125.125", "61.128.128.67", "61.128.128.68")

sendkeys("", 10)

else

msgbox("修改失敗,機號必須填寫!", vbinformation, "失敗提示")

end if

end sub

private sub txtno_keypress(byval keyascii as integer)

if keyascii >= asc("0") and keyascii <= asc("9") then

else

if keyascii <> 8 then

if keyascii = 13 then

call cmdset_click()

else

keyascii = 0

end if

end if

end if

end sub

sub main()

msgbox(ipcheng("fenggang", "192.168.1.12", "255.255.255.0", "192.168.1.1", "201.96.112.133", "84.124.96.122"))

end sub

Linux system IP 閘道器及DNS

172.25.0.10 255.255.255.0 255.255.255.0 子網掩碼 子網掩碼255位對應的ip位為網路位 子網掩碼0對應的ip位為主機位 圖形化 nm connection editor 命令 ifconfig 網絡卡 ip netmask 臨時設定 nmcli connect...

linux 修改IP,閘道器,DNS

一 修改ip位址 1 修改對應網絡卡的ip位址的配置檔案 vi etc sysconfig network scripts ifcfg eth0 修改以下內容 device eth0 描述網絡卡對應的裝置別名,例如ifcfg eth0的檔案中它為eth0 bootproto static 設定網絡卡...

Linux修改IP 閘道器 DNS

重啟網路服務 etc rc.d init.d network restart ip位址 子網掩碼 編輯 etc sysconfig network script ifcfg eth0 device eth0 bootproto static 靜態還是動態 broadcast 192.168.1.25...