internet ip address

internet ip address

Postby Richard Chidiak » Mon Nov 12, 2007 3:07 pm

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
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby Silvio » Mon Nov 12, 2007 4:57 pm

Code: Select all  Expand view
#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
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Postby Antonio Linares » Mon Nov 12, 2007 6:13 pm

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

Postby Silvio » Mon Nov 12, 2007 6:22 pm

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

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: internet ip address

Postby Enrico Maria Giordano » Mon Nov 12, 2007 9:23 pm

Code: Select all  Expand view
FUNCTION MAIN()

    LOCAL aHosts

    INETINIT()

    aHosts = INETGETHOSTS( NETNAME() )

    INETCLEANUP()

    ? aHosts[ 2 ]

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Mon Nov 12, 2007 9:38 pm

Enrico,

I get this error:
Code: Select all  Expand view
   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: 41315
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Tue Nov 13, 2007 11:01 am

Works fine here. Are you using Harbour or xHarbour?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Tue Nov 13, 2007 11:20 am

Enrico,

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

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

Postby Rossine » Tue Nov 13, 2007 11:24 am

Hello,

I use like this:

Code: Select all  Expand view

#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  Expand view

FUNCTION MAIN()

    LOCAL aHosts

    INETINIT()

    aHosts = INETGETHOSTS( NETNAME() )

    INETCLEANUP()

*   ? aHosts[ 2 ]
    ? valtoprg( aHosts )


Regards,

Rossine.
Rossine
 
Posts: 344
Joined: Tue Oct 11, 2005 11:33 am

Postby driessen » Tue Nov 13, 2007 5:13 pm

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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Enrico Maria Giordano » Tue Nov 13, 2007 6:21 pm

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
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby jose_murugosa » Wed Nov 14, 2007 3:15 am

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  Expand view
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
jose_murugosa
 
Posts: 1144
Joined: Mon Feb 06, 2006 4:28 pm
Location: Uruguay

Postby Antonio Linares » Wed Nov 14, 2007 6:49 am

José,

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

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

Postby Richard Chidiak » Wed Nov 14, 2007 8:41 am

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
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby Luca » Wed Nov 14, 2007 9:10 am

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
Luca
 
Posts: 1
Joined: Fri Dec 23, 2005 7:55 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 81 guests