什么是最简单的(模块包含,代码长度等)方式来检索机器IP地址(第一个接口打开)?我知道使用MSINET的一些解决方案,但我相信我们可以做得更好.不要回复
Function HomeIP() as Atring HomeIP= "127.0.0.1" End Function
因为它不那么有趣......或者说是正确的.这个场景是一个问题,我正在尝试建立一个回复文档ID功能.
以下是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 Scripting Library.