Page 1 of 1

Getting internal IP address

Posted: Fri Mar 09, 2012 7:43 am
by skiman
Hi,

I didn't see a function in the Xbtools.
What is the easiest way to get the internal ip-address. The address shown with ipconfig.

Re: Getting internal IP address

Posted: Fri Mar 09, 2012 8:23 am
by reganc
I noticed that Ot4xb from Pablo has IPCfg, would this work for you?

Re: Getting internal IP address

Posted: Fri Mar 09, 2012 8:30 am
by skiman
Hi Regan,

I would have thought that this was in ot4xb. I knew I saw it somewhere.

BTW, are you and/or Steve going to the Devcon?

Re: Getting internal IP address

Posted: Fri Mar 09, 2012 9:07 am
by reganc
skiman wrote:BTW, are you and/or Steve going to the Devcon?
Steve expressed an interest in us doing so a while back but hasn't mentioned it since. I will be bringing it up as a topic of conversation shortly and will let you know. I hope so...

Re: Getting internal IP address

Posted: Fri Mar 09, 2012 9:16 am
by skiman
Hi,

I downloaded the latest ot4xb, and tried the following functions:

Code: Select all

aEval(_aGetAdapterInfo(.T.,.T.), {|o| DisplayAdapter(o) } )
aEval(_aGetTcpTable(.t.)       , {|o| DisplayTcpConnection(o)})
aEval(_aGetUdpTable(.t.)       , {|o| DisplayUdpConnection(o)})
I can't get them compiled. Unresolved external symbol.

If I check the include files, I can't find these functions. Also not in the DOC file.

I have ot4xb.lib and ot4xbcpp.lib in my project file.

Any suggestions?

Re: Getting internal IP address

Posted: Fri Mar 09, 2012 5:00 pm
by Auge_Ohr
skiman wrote:I downloaded the latest ot4xb, and tried the following functions:

Code: Select all

aEval(_aGetAdapterInfo(.T.,.T.), {|o| DisplayAdapter(o) } )
aEval(_aGetTcpTable(.t.)       , {|o| DisplayTcpConnection(o)})
aEval(_aGetUdpTable(.t.)       , {|o| DisplayUdpConnection(o)})
I can't get them compiled. Unresolved external symbol.
did you have IPCFG.LIB / DLL ?
if not you have to use \Source\ipconfig.prg to build it

!need : advapi32.lib and Ws2_32.lib

... but there are other Version than IPCfg.zip which include IPCFG.LIB / DLL
search for Devcon 2007 WinApi_Tutor.zip ( 2.4MB )

Re: Getting internal IP address

Posted: Sat Mar 10, 2012 3:18 am
by skiman
Hi Jimmy,

Thanks to point me to the right direction. Also interesting PDF.

For who is interested in this.
http://www.xbwin.com/download/WinApi_Tutor.zip

Re: Getting internal IP address

Posted: Sat Mar 10, 2012 4:23 am
by skiman
Hi,

The following code returns an array with the IP adresses. It is based on ot4xb, see the above post.

Code: Select all

Function GetIPAdres()
*********************
Local aInfo := _aGetAdapterInfo(.T.,.T.) , aReturn := {} , x , cIp := ""

if valtype(aInfo) == "A"
	for x = 1 to len(aInfo)
	    cIp := aInfo[x]:aIPList[1]
	    if cIp # "0.0.0.0"
		aadd(aReturn,cIp )
	    endif
	next
	return aReturn
endif
return {}

Re: Getting internal IP address

Posted: Tue Mar 27, 2012 7:49 am
by rdonnay

Code: Select all

#INCLUDE "dcdialog.CH"
#INCLUDE "asinetc.CH"
#Pragma Library("asinet10.lib")

FUNCTION Main() // Get the IP address(es) of the local machine/returns array of dotted octet strings (example '192.168.0.102') or empty array if error

*constants from #include "Asinetc.ch"
*  HOSTINFO_CNAME  Character string containing the host name
*  HOSTINFO_ALIAS  One-dimensional array holding the alias names of the host.
*                  If no alias names exist, the array is empty.
*  HOSTINFO_NTYPE  Numeric value indicating address family.
*                  (always AF_INET for Windows sockets)
*  HOSTINFO_NLEN   Number of bytes required to encode the numeric IP address.
*
*  HOSTINFO_ADDR   One-dimensional array holding the numeric IP addresses
*                  of the host in network byte order.
******************************************************************************

LOCAL aHostInfo, nError := 0, aLocalIPaddress[0], i

aHostInfo := SocketGetHostByName('LOCALHOST',@nError) //Retrieves host information from a host name

if !Empty(aHostInfo)
  aHostInfo:=SocketGetHostByName(aHostInfo[HOSTINFO_CNAME],@nError) //Retrieves host information from a host name
  if !Empty(aHostInfo)
    for i := 1 TO Len(aHostInfo[HOSTINFO_ADDR])
      Aadd( aLocalIPaddress, SocketInetNtoA(aHostInfo[HOSTINFO_ADDR,i])) //Converts a numeric internet address in network byte order to a dotted octet string (returns 192.168.0.102)
    next
  endif
endif

wtf aLocalIPAddress pause

RETURN aLocalIPaddress