internet ip address

User avatar
Richard Chidiak
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France
Contact:

internet ip address

Post by Richard Chidiak »

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
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Post by Silvio »

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Richard,

This may help:
http://www.paulsadowski.com/sadowski/currentip.htm

Silvio,

Your code returns the local IP not the public IP on Internet
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Post by Silvio »

Antonio, sorry I not read good the text of Richard , sorry
Best Regards, Saludos

Falconi Silvio
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: internet ip address

Post by Enrico Maria Giordano »

Code: Select all

FUNCTION MAIN()

    LOCAL aHosts

    INETINIT()

    aHosts = INETGETHOSTS( NETNAME() )

    INETCLEANUP()

    ? aHosts[ 2 ]

    RETURN NIL
EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

I get this error:

Code: Select all

   Error description: Error BASE/1132  Bound error: array access
   Args:
     [   1] = A   { ... }
     [   2] = N   2
Using [ 1 ] then I get the local IP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

xHarbour, as Harbour does not provide those functions afaik
regards, saludos

Antonio Linares
www.fivetechsoft.com
Rossine
Posts: 343
Joined: Tue Oct 11, 2005 11:33 am

Post by Rossine »

Hello,

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
...or like this:

Code: Select all


FUNCTION MAIN() 

    LOCAL aHosts 

    INETINIT() 

    aHosts = INETGETHOSTS( NETNAME() ) 

    INETCLEANUP() 

*   ? aHosts[ 2 ] 
    ? valtoprg( aHosts )
Regards,

Rossine.
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post by driessen »

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 :
M->__ValToPrg_Array := Array(1)
M->__ValToPrg_Array[1] := "192.168.1.101"
which is my local IP too.
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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

driessen wrote:By using the example of Enrico, I got the same error as Antonio.
I don't understand. Do you want my EXE to test it there?

EMG
User avatar
jose_murugosa
Posts: 943
Joined: Mon Feb 06, 2006 4:28 pm
Location: Uruguay
Contact:

Post by jose_murugosa »

EnricoMaria wrote:
driessen wrote:By using the example of Enrico, I got the same error as Antonio.
I don't understand. Do you want my EXE to test it there?

EMG

Code: Select all

FUNCTION MAIN() 

   LOCAL aHosts 

   INETINIT() 
   aHosts = INETGETHOSTS( NETNAME() ) 
   INETCLEANUP() 
   MsgInfo( aHosts[ 2 ] )     <<<< aqui el cambio

RETURN NIL
Enrico I prove your sample and change ? with MsgInfo and then it works perfectly
Saludos/Regards,
José Murugosa
FWH + Harbour + Bcc7. Una seda!
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

José,

Code: Select all

   Error description: Error BASE/1132  Bound error: array access
   Args:
     [   1] = A   { ... }
     [   2] = N   2
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Richard Chidiak
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France
Contact:

Post by Richard Chidiak »

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
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Luca
Posts: 1
Joined: Fri Dec 23, 2005 7:55 am

Post by Luca »

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
Post Reply