熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

vb實現IP設置

2022-06-13   來源: .NET編程 

  這些天總是帶著筆記本在家/單位/客戶等等幾個地方跑來跑去的於是在各個地方上網都是要重新設置的有時候有線有時候無線昨天我終於爆發了再也受不了這麼沒有盡頭的折磨了於是我又用vb寫了一個簡單的IP設置轉換器(我已經上傳地址

  界面如下

  

  

  其實利用vb修改ip地址是比較容易的我利用的就是wmi方式先是找出當前系統的所有網卡信息下面給出的是找出所有網卡MAC地址的例程    Function GetMACaddress()
 
  Dim tempBool As Boolean strComputer =
 
  Set objWMIServiceGL = GetObject(winmgmts\\ & strComputer & \root\cimv
 
  Set colNetAdaptersGL = objWMIServiceGLExecQuery(Select * from Win_NetworkAdapterConfiguration where(IPEnabled=TRUE)
 
  For Each obj In objs
 
  getMACAddress = getMACAddress & objmacaddress & vbCrLf & vbCrLf
 
  Exit For  找第一個網卡就退出
 
  Next obj End Function
 
  然後根據所找到的各個網卡的進行信息(IPDNS等)更改    Function ModifyIP() strComputer =
 
  Set objWMIService = GetObject(winmgmts\\ & strComputer & \root\cimv
 
  Set objSWbemObjectSet = objSWbemServicesExecQuery(Select * From Win_NetworkAdapterConfiguration Where Description= & ComboText &
 
  For Each objNetAdapter In colNetAdapters sip = objNetAdapterIPaddress(
 
  If OptionValue = True Then DHCP is enabled
 
  objNetAdapterEnableDHCP
 
  errDNS = objNetAdapterSetDNSServerSearchOrder()
 
  Else strIPAddress = Array(TextText)
 
  strSubnetMask = Array(TextText)
 
  strGateway = Array(TextText)
 
  strGatewaymetric = Array(
 
  StrDns = Array(TextText TextText)
 
  errEnable = objNetAdapterEnableStatic(strIPAddress strSubnetMask)
 
  errGateways = objNetAdapterSetGateways(strGateway strGatewaymetric)
 
  errDNS = objNetAdapterSetDNSServerSearchOrder(StrDns)
 
  Exit For 只修改第一個網卡的設置
 
  End If Next End Function


From:http://tw.wingwit.com/Article/program/net/201311/13565.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.