internet ip address
- Richard Chidiak
- Posts: 946
- Joined: Thu Oct 06, 2005 7:05 pm
- Location: France
- Contact:
internet ip address
Hello
Is there an esay way to know the INTERNET ip address from a computer ?
I think Enrico published solething on it some time ago, i did a search but did not find,
if anyone has a sample, thanks for the help
PS : I was previously using tip functions from xharbour but they do not work anymore, i plan to replace them with fwh functions,
Thanks for help,
Richard
Is there an esay way to know the INTERNET ip address from a computer ?
I think Enrico published solething on it some time ago, i did a search but did not find,
if anyone has a sample, thanks for the help
PS : I was previously using tip functions from xharbour but they do not work anymore, i plan to replace them with fwh functions,
Thanks for help,
Richard
Code: Select all
#include "FiveWin.ch"
function Main()
local oSocket := TSocket():New( 2000 )
local cIp := oSocket:cIPAddr
?cIp
oSocket:End()
return NIL
Best Regards, Saludos
Falconi Silvio
Falconi Silvio
- Antonio Linares
- Site Admin
- Posts: 37485
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Richard,
This may help:
http://www.paulsadowski.com/sadowski/currentip.htm
Silvio,
Your code returns the local IP not the public IP on Internet
This may help:
http://www.paulsadowski.com/sadowski/currentip.htm
Silvio,
Your code returns the local IP not the public IP on Internet
- Enrico Maria Giordano
- Posts: 7356
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: internet ip address
Code: Select all
FUNCTION MAIN()
LOCAL aHosts
INETINIT()
aHosts = INETGETHOSTS( NETNAME() )
INETCLEANUP()
? aHosts[ 2 ]
RETURN NIL
- Antonio Linares
- Site Admin
- Posts: 37485
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Enrico,
I get this error:
Using [ 1 ] then I get the local IP
I get this error:
Code: Select all
Error description: Error BASE/1132 Bound error: array access
Args:
[ 1] = A { ... }
[ 2] = N 2
- Enrico Maria Giordano
- Posts: 7356
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
- Antonio Linares
- Site Admin
- Posts: 37485
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Hello,
I use like this:
...or like this:
Regards,
Rossine.
I use like this:
Code: Select all
#include "fivewin.ch"
function MAIN
msgstop( getip() )
return NIL
Function GetIP()
Local cVar1
WsaStartUp()
cVar1 := GetHostByName( GetHostName() )
WsaCleanUp()
return cVar1
Code: Select all
FUNCTION MAIN()
LOCAL aHosts
INETINIT()
aHosts = INETGETHOSTS( NETNAME() )
INETCLEANUP()
* ? aHosts[ 2 ]
? valtoprg( aHosts )
Rossine.
I tried the several possibilities.
By using the example of Enrico, I got the same error as Antonio.
The first example of Rossine returns my local IP.
The second example returns something like this :
By using the example of Enrico, I got the same error as Antonio.
The first example of Rossine returns my local IP.
The second example returns something like this :
which is my local IP too.M->__ValToPrg_Array := Array(1)
M->__ValToPrg_Array[1] := "192.168.1.101"
Regards,
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
- Enrico Maria Giordano
- Posts: 7356
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
- jose_murugosa
- Posts: 943
- Joined: Mon Feb 06, 2006 4:28 pm
- Location: Uruguay
- Contact:
EnricoMaria wrote:I don't understand. Do you want my EXE to test it there?driessen wrote:By using the example of Enrico, I got the same error as Antonio.
EMG
Code: Select all
FUNCTION MAIN()
LOCAL aHosts
INETINIT()
aHosts = INETGETHOSTS( NETNAME() )
INETCLEANUP()
MsgInfo( aHosts[ 2 ] ) <<<< aqui el cambio
RETURN NIL
Saludos/Regards,
José Murugosa
FWH + Harbour + Bcc7. Una seda!
José Murugosa
FWH + Harbour + Bcc7. Una seda!
- Antonio Linares
- Site Admin
- Posts: 37485
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
José,
Code: Select all
Error description: Error BASE/1132 Bound error: array access
Args:
[ 1] = A { ... }
[ 2] = N 2
- Richard Chidiak
- Posts: 946
- Joined: Thu Oct 06, 2005 7:05 pm
- Location: France
- Contact:
Antonio,
Unfortunately all the samples above retreive the Local ip code not the internet one
I have a function that retreives a html page and reads it, the problem it is not a 100% secure function as the page might change....
This is why i was looking for a replacement,
here is the function anyway,
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:=tipclienthttp():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
END
fclose(hFile)
erase (cfile)
ENDIF
return ALLTRIM(myip)
Richard
Unfortunately all the samples above retreive the Local ip code not the internet one
I have a function that retreives a html page and reads it, the problem it is not a 100% secure function as the page might change....
This is why i was looking for a replacement,
here is the function anyway,
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:=tipclienthttp():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
END
fclose(hFile)
erase (cfile)
ENDIF
return ALLTRIM(myip)
Richard
func GetMyIP( cURL )
#include "tip.ch"
local cMyIP := ""
local oUrl, oClient
cURL := if( empty(cURL), "http://www.whatismyip.org/", cURL )
oUrl := tURL():New( cURL )
if !empty( oUrl )
oClient := tIPclient():new( oUrl )
if !empty( oClient )
oClient:nConnTimeOut := 20000
if oClient:Open( oUrl )
cMyIP := oClient:Read(80)
oClient:Close()
endif
endif
endif
return cMyIP
#include "tip.ch"
local cMyIP := ""
local oUrl, oClient
cURL := if( empty(cURL), "http://www.whatismyip.org/", cURL )
oUrl := tURL():New( cURL )
if !empty( oUrl )
oClient := tIPclient():new( oUrl )
if !empty( oClient )
oClient:nConnTimeOut := 20000
if oClient:Open( oUrl )
cMyIP := oClient:Read(80)
oClient:Close()
endif
endif
endif
return cMyIP