AutoHotkey v2 alpha (UPDATES) - Page 3 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 06#p242306
So I'm seeking to backport this function to AHK v1. To recreate it.
commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=29689
This is the code I will probably use:
Code: Select all
MsgBox, % SysGetIPAddresses().Length()
MsgBox, % SysGetIPAddresses().1
SysGetIPAddresses()
{
local IPAddress, List
List := []
Loop 4
{
IPAddress := A_IPAddress%A_Index%
if !(IPAddress = "0.0.0.0")
List.Push(IPAddress)
}
return List
}
There's also this, as another reason:
AutoHotkey via DllCall: AutoHotkey functions as custom functions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=37871
I based my code on these links (and the MSDN pages for Winapi structs/functions):
Pop3 Mail Check Filter (no Gui) - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/4403 ... er-no-gui/
#exclude for Excluding Components - Suggestions - AutoHotkey Community
https://autohotkey.com/board/topic/7000 ... omponents/
Replaced A_IPAddressX with SysGetIPAddresses(). · Lexikos/[email protected] · GitHub
https://github.com/Lexikos/AutoHotkey_L ... a22b2aa642
My code works, but I only had 1 IP address, so I couldn't test for further addresses.
I present it here in case others can test it/fix it for additional IP addresses.
(I'll probably stick with the simpler function above though, for my backport library.)
Btw do other users have multiple IP addresses? Ever more than 4? Thanks.
Code: Select all
q:: ;recreate A_IPAddressXXX variables
;IP_ADDRESS_SIZE := 32
VarSetCapacity(WSADATA, A_PtrSize=8?408:400, 0)
if DllCall("ws2_32\WSAStartup", UShort,0x101, Ptr,&WSADATA)
return
VarSetCapacity(vHostName, 256, 0)
DllCall("ws2_32\gethostname", Ptr,&vHostName, Int,256)
MsgBox, % StrGet(&vHostName, "CP0")
if ((pHOSTENT := DllCall("ws2_32\gethostbyname", Ptr,&vHostName, "Cdecl Ptr")) != 0)
{
Loop, 1
{
vOffset:=(A_Index-1)*4
pTemp := NumGet(pHOSTENT+(A_PtrSize=8?24:12))
if (pTempIP := NumGet(pTemp+vOffset*2))
{
vIPAddress := ""
Loop, 4
vIPAddress .= NumGet(pTempIP+vOffset, A_Index-1, "UChar") "."
vIPAddress := SubStr(vIPAddress, 1, -1)
}
else
break
}
}
DllCall("ws2_32\WSACleanup")
MsgBox, % vIPAddress "`r`n" A_IPAddress1
return