X++:
static void GetClientIP(Args _args)
{
xSession session = new xSession();
container Addr;
int k;
container GetHostByName(str Host)
{
DLL dll = new DLL("Ws2_32.dll");
DLLFunction _getHostByName = new DLLFunction(dll, "gethostbyname");
DLLFunction _inet_ntoa = new DLLFunction(dll, "inet_ntoa");
int Hostent;
Binary bin = new Binary(16);
Binary h, h1;
int i;
container c = connull();
str s;
;
_getHostByName.arg(ExtTypes::String);
_getHostByName.returns(ExtTypes::DWord);
Hostent = _getHostByName.Call(Host);
if (Hostent)
{
bin.attach(Hostent, 16);
if (bin.word(8) == 2 && bin.word(10) == 4)
{
h = new Binary(4*251);
h.attach(bin.DWord(12), 4*251);
_inet_ntoa.arg(ExtTypes::DWord);
_inet_ntoa.returns(ExtTypes::String);
h1 = new Binary(bin.word(10));
for (i=0;h.DWord(i);i+=4)
{
h1.attach(h.DWord(i), bin.word(10));
s = _inet_ntoa.call(h1.DWord(0));
if (s)
c += [s];
}
}
}
return c;
}
;
Addr = GetHostByName(Session.clientComputerName());
for (k=1;k<=ConLen(Addr);k++)
info(ConPeek(Addr, k));
}