Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
System IP
#1
Whats the variable/function for determining current IP config of the system ? XP/Vista both.
IBM Mainframe Expert who Plays with QM a LOT !
#2
Function GetIpAddress2
Code:
Copy      Help
;/
function# $computer str&ip [flags] ;;flags: 1 get all

;Retrieves IP address of computer.
;Returns 1 on success, 0 on failure.
;For local computer name, use "".
;If flag 1 used, gets list of IP addresses of the computer.
;computer can be like computer:port. Then IP will be like ip:port.

;EXAMPLE
;str ip
;if(GetIpAddress2("PC-3" ip))
,;out ip


if(!GetEnvVar("qm_wsa" _s) or !_s.len)
,SetEnvVar "qm_wsa" 1
,WSADATA wsaData
,WSAStartup(0x0002 &wsaData)

ip=""

;if computer:port, separate, and later append port to IP
str cn port
int nt=tok(computer &cn 2 ":")
if(nt>1) computer=cn

if(empty(computer)) computer=0
hostent* hp = gethostbyname(computer); if(!hp) ret
int i
for i 0 1000
,if(hp.h_addr_list[i] && hp.h_length>=4) else break
,byte* b=hp.h_addr_list[i]
,int* ipi=b; if(*ipi=0x100007F) continue ;;"127.0.0.1"
,if(i) ip+"[]"
,ip.formata("%u.%u.%u.%u" b[0] b[1] b[2] b[3])
,if(nt>1) ip.formata(":%s" port)
,if(flags&1=0) break
ret ip.len!=0


This function will be in next QM version.


Forum Jump:


Users browsing this thread: 1 Guest(s)