Monday, January 21, 2008

How to get the PC Name and IP

static void JobGetServerInfo(Args _args)
{
xSession curXS;
int i;

str GetIP(str Hostname)
{
DLL DLL = new DLL("ws2_32.dll");
DLL DLL2 = new DLL("kernel32");
DLLFunction CopyMemory = new DLLFunction(Dll2, "RtlMoveMemory");
DLLFunction HostInfo = new DLLFunction(DLL, "gethostbyname");
binary Dest = new binary(100);
int Host;
str IP;

HostInfo.arg(ExtTypes::String);
HostInfo.returns(ExtTypes::DWord);
Host = HostInfo.call(Hostname);

CopyMemory.arg(ExtTypes::Pointer,
ExtTypes::DWord,
ExtTypes::DWord);
if(Host)
{
CopyMemory.call(Dest, Host, 16);
if(Dest.dWord(12))
{
CopyMemory.call(Dest, Dest.dWord(12), 4);

if(Dest.dWord(0))
{
CopyMemory.call(Dest, Dest.dWord(0), 4);
IP = int2str(Dest.byte(0)) + "." +
int2str(Dest.byte(1)) + "." +
int2str(Dest.byte(2)) + "." +
int2str(Dest.byte(3));
}
}
}
return IP;
}
;
for(i = 1; i <= Info::licensedUsersTotal(); i++)
{
curXS = new xSession(i, true);
if(curXS && curXS.sessionId() &&
curXS.clientKind() == ClientType::Client && curXS.userId())
{
info( "PC Name:"+curXS.clientComputerName() + ", IP:"+getIP( curXS.clientComputerName())); //pause;
}
}
}

No comments: