问题:如何用AutoHotkey v2 获取本地IP地址。
解答:AutoHotkey v2 源代码如下
#Requires AutoHotkey v2; MsgBox GetLocalIPByAdapter('Ethernet') ; <— specify the adapter name you are interested in
; MsgBox GetLocalIPByAdapter('以太网') ; <— specify the adapter name you are interested in
MsgBox GetLocalIPByAdapter('WLAN') ; <— specify the adapter name you are interested inGetLocalIPByAdapter(adapterName) {wmi := ComObjGet('winmgmts:')adapters := wmi.InstancesOf('Win32_NetworkAdapter where NetConnectionID = "' . adapterName . '"')if adapters.Count {adapter := adapters.ItemIndex(0)ipAddressArr := wmi.InstancesOf('Win32_NetworkAdapterConfiguration where InterfaceIndex = "' . adapter.InterfaceIndex . '"').ItemIndex(0).IPAddressreturn ipAddressArr is ComObjArray ? ipAddressArr[0] : '"' . adapterName . '" disconnected'}return '"' . adapterName . '" not found'
}