Getting internal IP address

This forum is for eXpress++ general support.
Post Reply
Message
Author
skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Getting internal IP address

#1 Post 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.
Best regards,

Chris.
www.aboservice.be

reganc
Posts: 257
Joined: Thu Jan 28, 2010 3:08 am
Location: Hersham, Surrey, UK
Contact:

Re: Getting internal IP address

#2 Post by reganc »

I noticed that Ot4xb from Pablo has IPCfg, would this work for you?
Regan Cawkwell
Real Business Applications Ltd
http://www.rbauk.com

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Getting internal IP address

#3 Post 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?
Best regards,

Chris.
www.aboservice.be

reganc
Posts: 257
Joined: Thu Jan 28, 2010 3:08 am
Location: Hersham, Surrey, UK
Contact:

Re: Getting internal IP address

#4 Post 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...
Regan Cawkwell
Real Business Applications Ltd
http://www.rbauk.com

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Getting internal IP address

#5 Post 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?
Best regards,

Chris.
www.aboservice.be

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: Getting internal IP address

#6 Post 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 )
greetings by OHR
Jimmy

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Getting internal IP address

#7 Post 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
Best regards,

Chris.
www.aboservice.be

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Getting internal IP address

#8 Post 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 {}
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Getting internal IP address

#9 Post 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
The eXpress train is coming - and it has more cars.

Post Reply