获取程序使用的内网IP地址
PROCEDURE getip
LOCAL dwSize, stTable, nTableCount,
dwLocalAddr, dwOwningPid,szLocalAddr,CurrentProcessId,ii
store "0.0.0.0" TO dwLocalAddr
Declare Integer GetCurrentProcessId In kernel32.Dll
DECLARE LONG GetExtendedTcpTable IN "Iphlpapi.dll" STRING@, LONG@, LONG, LONG, LONG, LONG
DECLARE LONG inet_ntoa IN "Ws2_32" LONG
DECLARE LONG ntohs IN "Ws2_32" LONG
DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
DECLARE Long GetModuleFileNameEx IN PsApi
Long hProcess, Long hModule, String @ lpExename, Long dwSize
DECLARE Long OpenProcess IN WIN32API Long dwDesiredAccess, Long bInheritHandle, Long dwProcessId
CurrentProcessId=GetCurrentProcessId()
dwSize=0
GetExtendedTcpTable(NULL, @dwSize, 1, 2, 5, 0) && TCP_TABLE_OWNER_PID_ALL
IF m.dwSize > 0
stTable = REPLICATE(0h0, m.dwSize) && 分配数据空间
GetExtendedTcpTable(@stTable, @dwSize, 1, 2, 5, 0)
nTableCount = CTOBIN(SUBSTR(m.stTable, 1, 4), "4Rs")
IF m.nTableCount > 0
stTable = STUFF(m.stTable, 1, 4, "")
FOR ii = 1 TO m.nTableCount
szLocalAddr = CTOBIN(SUBSTR(m.stTable, 5, 4), "4R")+2^31 && 本地 IP地址
szLocalAddr = SYS(2600, inet_ntoa(m.szLocalAddr), 16)
szLocalAddr = LEFT(szLocalAddr, AT(0h00, m.szLocalAddr)-1)
dwOwningPid = CTOBIN(SUBSTR(m.stTable, 21, 4), "4R")+2^31 && 关联的进程ID
IF m.CurrentProcessId=m.dwOwningPid
dwLocalAddr=m.szLocalAddr
exit
endif
stTable = STUFF(m.stTable, 1, 24, "")
NEXT
ENDIF
ENDIF
retu m.dwLocalAddr