Game Development Community

How do I get local ip address?

by Howard Dortch · in Torque Game Engine · 07/04/2007 (6:43 am) · 2 replies

I want to get the ip address of any box on my lan (linksys router). ipconfig tells me from command line but I want to get it from the engine. Someone point me in the right direction?

#1
07/06/2007 (5:00 pm)
Exec an external program and read the output. You could probably jimmy up some torque script calls to do it from script. I am not sure of a way to do it in the engine as is. There may be, you could delve into the netcode to try and determine if there is a better way to do this. There might even be script code to do it. I have used some TCP based commands to get stock quotes into the engine.
#2
07/06/2007 (5:21 pm)
In windows,
if you want to get hardcore,
you might check out calls like
queryWMI("SELECT * FROM Win32_NetworkAdapterConfiguration", readNetworkAdapterConfiguration);
and an associated function like
HRESULT readNetworkAdapterConfiguration(IWbemClassObject* obj)
{
   const char* ipString = dStrdup(_getStringProp(obj, L"IPAddress"));
   if (dStrcmp(ipString, "") != 0)
   {
      _wmiLog("---Network Adapter--");
      _wmiLog("Name: %s", _getStringProp(obj, L"Caption"));
      
      const char* mac = _getStringProp(obj, L"MACAddress");

      setSystemString("System::ID1", mac);

      _wmiLog("MAC: %s", mac);      
      _wmiLog("DNSDomain: %s", _getStringProp(obj, L"DNSDomain"));
      _wmiLog("DHCPServer: %s", _getStringProp(obj, L"DHCPServer"));
      _wmiLog("Lease Obtained: %s", _getStringProp(obj, L"DHCPLeaseObtained"));
      _wmiLog("Lease Expires: %s", _getStringProp(obj, L"DHCPLeaseExpires"));
      _wmiLog("IP: %s", ipString);
      _wmiLog("Subnet: %s", _getStringProp(obj, L"IPSubnet"));
      _wmiLog("Gateway: %s", _getStringProp(obj, L"DefaultIPGateway"));
      _wmiLog("");
   }
   if (ipString)
      dFree((void*)ipString);
   return 0;
}