FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ip address
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
ip address
Posted: Wed Feb 01, 2006 10:19 AM

Hello

How can we know the pc ip address on the internet

Gethostbyname(pcname) returns the internal ip
gethostbyname("www.......") returns the web page's address

I am interested to know at one moment my own ip address on the web

Thanks for the help

Richard

http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
ip address
Posted: Wed Feb 01, 2006 04:03 PM

FUNCTION GetIP()
local oSocket := TSocket():New( 2000 ), nIp := oSocket:cIPAddr
oSocket:End()
RETURN (nIp)

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
ip address
Posted: Wed Feb 01, 2006 06:04 PM

James,

Added to FWH, thanks

ops, it shows the LAN IP, not the Internet IP...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
ip address
Posted: Wed Feb 01, 2006 09:23 PM
Antonio Linares wrote:James,

Added to FWH, thanks

ops, it shows the LAN IP, not the Internet IP...


Right,


I hope to have a function for retreiving the Internet IP very soon. I have the information available at the moment in a txt file.
I need to parse this txt file quickly to search for a string (It is a xml file basically) any idea ?
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
ip address
Posted: Wed Feb 01, 2006 10:07 PM
Richard Chidiak wrote:
Antonio Linares wrote:James,

Added to FWH, thanks

ops, it shows the LAN IP, not the Internet IP...


Right,


I hope to have a function for retreiving the Internet IP very soon. I have the information available at the moment in a txt file.
I need to parse this txt file quickly to search for a string (It is a xml file basically) any idea ?



Here is the function :-)

#INCLUDE "FIVEWIN.CH"
#include "tip.ch"
local myip := getmyip()


function getmyip()
LOCAL aEol := { Chr(13) + Chr(10), Chr(10) }, ;
ctr := 0, ;
lok := .f., ;
myip := space(80), ;
sLine,cfile

cfile := CURDRIVE() + ":" + CURDIR() + "\myip.txt"

IF FILE(CFILE)
ERASE (CFILE)
ENDIF
oUrl := tURL():New( "http://www.adresseip.com/" )
IF Empty( OUrl )
MSGINFO("URL NOT FOUND")
RETURN NIL
ENDIF

oClient := tIPClient():New( oUrl )
IF Empty( oClient )
MSGINFO("Invalid url ")
RETURN NIL
ENDIF

oClient:nConnTimeout := 20000
IF oClient:Open( oUrl )
IF ! oClient:ReadToFile( cFile )
MSGINFO("Generic error in writing." + cFile)
ENDIF
oClient:Close()
endif

IF FILE(CFILE)
hFile := FOPEN(CFILE)
WHILE HB_FReadLine( hFile, @sLine, aEol ) == 0
ctr++
IF subs(ALLTRIM(sLine),1,8) == "<SPAN ID" // ip is next line
ctr := 1
lok := .t.
ENDIF
IF CTR = 2 .AND. lok
myip := sline
ENDIF

// ? sLine
END
fclose(hFile)
ENDIF
return myip
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013

Continue the discussion