wxyo19870519 发表于 2010-5-7 16:09:00

通过VBA实现IP地址查询(固定)!

本帖最后由 作者 于 2010-5-10 9:20:37 编辑 <br /><br /> <p>各位高手我有点事情想请教下,怎样在vba中用函数定义实现ip地址查询呢?<br/>也就是说我知道一些IP,怎样来判断它是南通或者北京(这些ip就是是南通和北京的)?<br/>怎么在vba里面实现啊!请指教我下。。。。</p><p></p><p>例子;</p><p>Public Sub GetMyIP()<br/>&nbsp;&nbsp;&nbsp; Dim strComputer As String<br/>&nbsp;&nbsp;&nbsp; Dim objWMI As Object<br/>&nbsp;&nbsp;&nbsp; Dim colIP As Object<br/>&nbsp;&nbsp;&nbsp; Dim IP As Object<br/>&nbsp;&nbsp;&nbsp; Dim i As Integer</p><p>&nbsp;&nbsp;&nbsp; strComputer = "."<br/>&nbsp;&nbsp;&nbsp; Set objWMI = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2")<br/>&nbsp;&nbsp;&nbsp; Set colIP = objWMI.ExecQuery _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; For Each IP In colIP<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not IsNull(IP.IPAddress) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = LBound(IP.IPAddress) To UBound(IP.IPAddress)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox IP.IPAddress(i), vbInformation, IP.Description(i)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Next</p><p>End Sub</p><p>我只能查询本机的IP ,怎么才能实现查询访问的IP呢?并且进行对比。</p>
页: [1]
查看完整版本: 通过VBA实现IP地址查询(固定)!