如何检索这台电脑的IP地址? [英] How to retrieve this computer's IP address?
本文介绍了如何检索这台电脑的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
检索机器IP地址(第一个接口打开)的方式最不方便(模块包含,代码长度等)是什么?
我知道使用MSINET的一些解决方案,但我相信我们可以做得更好。
不要回复
What is the least cumbersome (module-inclusion, code lenght, etc) way to retrieve the machine IP address (of the first interface open)? I know of some solutions using MSINET, but I believe we can do better. Don't reply
Function HomeIP() as Atring
HomeIP= "127.0.0.1"
End Function
因为这不是很有趣...或正确。
该方案是一个问题,一个文档ID功能我'我试图建立一个答复。
because it's not that funny... or correct. The scenario is a question wiht a document ID feature I'm trying to build a reply for.
推荐答案
以下是 Technet :
Function GetIPAddress()
Const strComputer As String = "." ' Computer name. Dot means local computer
Dim objWMIService, IPConfigSet, IPConfig, IPAddress, i
Dim strIPAddress As String
' Connect to the WMI service
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
' Get all TCP/IP-enabled network adapters
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
' Get all IP addresses associated with these adapters
For Each IPConfig In IPConfigSet
IPAddress = IPConfig.IPAddress
If Not IsNull(IPAddress) Then
strIPAddress = strIPAddress & Join(IPAddress, ", ")
End If
Next
GetIPAddress = strIPAddress
End Function
它要求您在项目的引用中具有Microsoft WMI脚本库。
It requires that you have Microsoft WMI Scripting Library in the project's references.
这篇关于如何检索这台电脑的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文