TGC Codebase Backup



Identify your IP address by IanM

31st Aug 2003 9:38
Summary

Detect all IP addresses assigned to your machine.



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    sync on

if WSAStartup() = 0
   print GetLocalIP(0)
   print GetLocalIP(1)
   WSACleanup()
endif

sync
sync
wait key

end

function GetLocalIPCount()
   local Count as integer
   local p as DWORD
   local v as DWORD
   local HOSTENT as DWORD

   HOSTENT=make memory(256)
   Count=0

   if GetHostName( HOSTENT, 256 ) = 0
      HostInfo=GetHostByName( HOSTENT )
      if HostInfo <> 0
         p=HostInfo+12
         p=*p
         do
            v=*p
            if v = 0 then exit
            inc p, 4
            inc Count
         loop
      endif
   endif

   delete memory HOSTENT
endfunction Count

function GetLocalIP(index as integer)
   local ip as string
   local p as DWORD
   local HOSTENT as DWORD

   HOSTENT=make memory(256)

   if GetHostName( HOSTENT, 256 ) = 0
      HostInfo=GetHostByName( HOSTENT )
      if HostInfo <> 0
         p=HostInfo+12
         p=*p
         p=*p
         p=p+(index*4)
         ip=INET_ntoa( *p )
      endif
   endif

   delete memory HOSTENT
endfunction ip

function GetHostName(memptr as DWORD, size as integer)
   local r as integer
   local a as DWORD
   local s as DWORD
   r=call dll(201, "gethostname", memptr, size)
endfunction r

function GetHostByName(memptr as DWORD)
   local r as integer
   r=call dll(201, "gethostbyname", memptr)
endfunction r

function INET_ntoa(addr as DWORD)
   local ip as string
   ip=call dll(201, "inet_ntoa", addr)
endfunction ip

function WSAStartup()
   local WSADATA as DWORD
   local r as integer
   local v as WORD

   load dll "wsock32.dll",201

   WSADATA=make memory(16384)

   v=2
   r=call dll(201, "WSAStartup", v, WSADATA)

   delete memory WSADATA
endfunction r

function WSACleanup()
   call dll 201, "WSACleanup"
   delete dll 201
endfunction