vb6.0
需要引用microsoft wmi scripting
**為了便於修改,ip未做處理
初衷(當前**)只改預設閘道器
192.168.199.200和192.168.199.253之間切換
dim pd
dim lip
option explicit '這是窗體**
private
sub command3_click(
) pd =
1 msgbox changeip(
"1",
"255.255.255.0"
,"192.168.1.1"
,"202.98.192.67"
,"202.98.198.167"
)end
subprivate
sub command4_click(
) pd =
2 msgbox changeip(
"1",
"255.255.255.0"
,"192.168.1.1"
,"202.98.192.67"
,"202.98.198.167"
)end
sub'更改ip
function changeip(
ipas
string
, nm as
string
, gw as
string
, mdns as
string
, sdns as
string)as
string
if pd =
1then
gw =
"192.168.199.200"
else
gw =
"192.168.199.253"
endif
dim winip as
object
set winip = createobject(
"mswinsock.winsock")ip
= winip.localip
dim strcomputer, objwmiservice, colnetadapters, stripaddress, strsubnetmask
dim strgateway, strgatewaymetric, strdns, objnetadapter, errenable, errgateways, errdns
strcomputer =
"."set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colnetadapters = objwmiservice.execquery(
"select * from win32_networkadapterconfiguration where ipenabled=true"
) stripaddress =
array(ip
)'ip位址
strsubnetmask =
array
(nm)
'子網 strgateway =
array
(gw)
'閘道器 strdns =
array
(mdns, sdns)
'main dns and second 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 =
0and errgateways =
0and errdns =
0then
changeip = "網路資訊更新成功,好好幹!"
else
if errenable =
0then
changeip = "ip位址和子網成功, "
else
changeip = "ip位址或子網置 x, "
endifif errgateways =
0then
changeip = changeip & "default成功, "
else
changeip = changeip &
"default x, "
endif
if errdns =
0then
changeip = changeip & "dns成功"
else
changeip = changeip &
"dns x"
endif
endif
next
endfunction
Linux更改IP位址
以華北工控的3151板子為例 系統下有ifupdown和dhcpcd兩套軟體可用來管理網路,開機啟動指令碼分別為 etc init.d s40network和 etc init.d s41dhcpcd,ifupdown的配置檔案為 etc network inte ces,dhcpcd的配置檔案為 ...
ubuntu更改ip位址
通過編輯 etc network inte ces可以修改各個網絡卡的位址。auto lo iface lo inet loopback auto ens38 開機自啟 iface ens38 inet static 設定為靜態位址 address 192.168.1.1 ip位址 netmask ...
系統資訊獲取 10,獲取本機IP位址
使用上文所說的 方法得到主機名,再使用函式 gethostbyname 可以得到 hostent結構的主機實體。當中儲存了主機的一些資訊,包括ip。gethostbyname 原型 struct hostent far wsaapi gethostbyname in const char far n...