IP Publica
Moderator: Rathinagiri
-
- Posts: 269
- Joined: Wed Aug 13, 2008 2:35 pm
- Location: Córdoba - Argentina
IP Publica
Hola Amigos :
necesito implementar con HMG una aplicacion que me vizualize la IP publica de la pc donde estoy conectado .
Tiene Harbour funciones que me permitan realizar esto ? .
De lo contario alguien conoce una aplicacion externa que me permita obtener esta informacion .
Saludos cordiales
Mario Mansilla
Hello friends :
I need to implement with HMG an application that will visualize the public IP of the pc where I am connected.
Does Harbor have functions that allow me to do this? .
Otherwise someone knows an external application that allows me to obtain this information.
Best regards
Mario Mansilla
necesito implementar con HMG una aplicacion que me vizualize la IP publica de la pc donde estoy conectado .
Tiene Harbour funciones que me permitan realizar esto ? .
De lo contario alguien conoce una aplicacion externa que me permita obtener esta informacion .
Saludos cordiales
Mario Mansilla
Hello friends :
I need to implement with HMG an application that will visualize the public IP of the pc where I am connected.
Does Harbor have functions that allow me to do this? .
Otherwise someone knows an external application that allows me to obtain this information.
Best regards
Mario Mansilla
Re: IP Publica
Hola Mario
Quizá esto te de una pista de como hacerlo con HMG
-------------------------------------------------------------------
Hello Mario
Maybe this gives you a clue on how to do it with HMG
viewtopic.php?f=24&t=3488&p=32282&hilit ... ezl#p32282
Quizá esto te de una pista de como hacerlo con HMG
-------------------------------------------------------------------
Hello Mario
Maybe this gives you a clue on how to do it with HMG
viewtopic.php?f=24&t=3488&p=32282&hilit ... ezl#p32282
Andrés González López
Desde Guadalajara, Jalisco. México.
Desde Guadalajara, Jalisco. México.
Re: IP Publica
Hi Mario,
There are different ways to get the Public IP:
You can use the following code:
#include "hmg.ch"
function main
local cInternetIP := Ip_Externo()
cInternetIP := iif("Site" $ upper(cInterNetIP),cInterNetIP,;
"Internet IP is: "+cInterNetIP)
/*
if file("init.cld")
REQUEST HB_GT_WIN_DEFAULT
endif
*/
DEFINE WINDOW Win_1 ;
AT 0,0 ;
WIDTH 300 ;
HEIGHT 170 ;
TITLE 'Internet IP Address' ;
MAIN ;
NOSIZE ;
NOMAXIMIZE ;
TOPMOST
@ 30,25 LABEL label_1 of Win_1 VALUE cInternetIP ;
WIDTH 250 ;
BORDER ;
BOLD ;
font "Arial" SIZE 11 ;
CENTERALIGN ;
CLIENTEDGE ;
TOOLTIP "Your internet IP"
@ 80,90 BUTTON button_1 of Win_1 CAPTION "Ok " ACTION Win_1.Release ;
TOOLTIP "Click OK to exit"
END WINDOW
Win_1.Center
ACTIVATE WINDOW Win_1
return NIL
FUNCTION IP_EXTERNO()
local url, html, vRet := " ",oError
url := "http://checkip.dyndns.org/" //'http://meuip.datahouse.com.br/ automation.whatismyip.com/n09230945.asp'
TRY
html:= ReadPage_ler( url )
memowrit(GetMyDocumentsFolder()+"\InterNetIPInfo.html",dtoc(date())+" "+time()+" ["+html+"]")
vRet := PegaIP_ex(html) //vRET:= html //
CATCH oError
MsgBox(oError:Description,"Error:")
vRet := "Error In Connecting."
END
RETURN iif(empty(vRET),"Site Not Reachable!",vRet)
FUNCTION PegaIP_ex(cHtml)
LOCAL Pos, PosF
Pos := At(':', Upper(cHtml) )
IF Pos < 1
RETURN 0
ENDIF
* Pos += Len('IP?')
cHtml := subst( cHtml, Pos+1 )
PosF := At('<',Upper(cHtml)) - 1
cHtml := Subst(cHtml,1,PosF)
RETURN alltrim(cHtml)
FUNCTION ReadPage_ler( cUrl )
LOCAL oUrl, oCli, cRes := ''
BEGIN SEQUENCE
oUrl = TUrl():New( cUrl )
IF EMPTY( oUrl )
BREAK
ENDIF
oCli = TIpClientHttp():New( oUrl )
IF EMPTY( oCli )
BREAK
ENDIF
oCli:nConnTimeout = 20000
IF !oCli:Open( oUrl )
BREAK
ENDIF
cRes := oCli:Read()
oCli:Close()
END SEQUENCE
RETURN cRes
HTH,
Warm regards,
Jayadev
There are different ways to get the Public IP:
You can use the following code:
#include "hmg.ch"
function main
local cInternetIP := Ip_Externo()
cInternetIP := iif("Site" $ upper(cInterNetIP),cInterNetIP,;
"Internet IP is: "+cInterNetIP)
/*
if file("init.cld")
REQUEST HB_GT_WIN_DEFAULT
endif
*/
DEFINE WINDOW Win_1 ;
AT 0,0 ;
WIDTH 300 ;
HEIGHT 170 ;
TITLE 'Internet IP Address' ;
MAIN ;
NOSIZE ;
NOMAXIMIZE ;
TOPMOST
@ 30,25 LABEL label_1 of Win_1 VALUE cInternetIP ;
WIDTH 250 ;
BORDER ;
BOLD ;
font "Arial" SIZE 11 ;
CENTERALIGN ;
CLIENTEDGE ;
TOOLTIP "Your internet IP"
@ 80,90 BUTTON button_1 of Win_1 CAPTION "Ok " ACTION Win_1.Release ;
TOOLTIP "Click OK to exit"
END WINDOW
Win_1.Center
ACTIVATE WINDOW Win_1
return NIL
FUNCTION IP_EXTERNO()
local url, html, vRet := " ",oError
url := "http://checkip.dyndns.org/" //'http://meuip.datahouse.com.br/ automation.whatismyip.com/n09230945.asp'
TRY
html:= ReadPage_ler( url )
memowrit(GetMyDocumentsFolder()+"\InterNetIPInfo.html",dtoc(date())+" "+time()+" ["+html+"]")
vRet := PegaIP_ex(html) //vRET:= html //
CATCH oError
MsgBox(oError:Description,"Error:")
vRet := "Error In Connecting."
END
RETURN iif(empty(vRET),"Site Not Reachable!",vRet)
FUNCTION PegaIP_ex(cHtml)
LOCAL Pos, PosF
Pos := At(':', Upper(cHtml) )
IF Pos < 1
RETURN 0
ENDIF
* Pos += Len('IP?')
cHtml := subst( cHtml, Pos+1 )
PosF := At('<',Upper(cHtml)) - 1
cHtml := Subst(cHtml,1,PosF)
RETURN alltrim(cHtml)
FUNCTION ReadPage_ler( cUrl )
LOCAL oUrl, oCli, cRes := ''
BEGIN SEQUENCE
oUrl = TUrl():New( cUrl )
IF EMPTY( oUrl )
BREAK
ENDIF
oCli = TIpClientHttp():New( oUrl )
IF EMPTY( oCli )
BREAK
ENDIF
oCli:nConnTimeout = 20000
IF !oCli:Open( oUrl )
BREAK
ENDIF
cRes := oCli:Read()
oCli:Close()
END SEQUENCE
RETURN cRes
HTH,
Warm regards,
Jayadev
Re: IP Publica
This was some code I had found on the net, which I have modified to suit my purpose. Credit is due to the Author of the code.
Warm regards,
Jayadev
Warm regards,
Jayadev
-
- Posts: 269
- Joined: Wed Aug 13, 2008 2:35 pm
- Location: Córdoba - Argentina
Re: IP Publica
Hola Jayadev :
muchas gracias por tu repuesta , no puedo hacer funcionar tu codigo .
Te envio mi proyecto hecho con el IDE de HMG 3.4.4.
No se que error estoy cometiendo
Saludos
Mario Mansilla
muchas gracias por tu repuesta , no puedo hacer funcionar tu codigo .
Te envio mi proyecto hecho con el IDE de HMG 3.4.4.
No se que error estoy cometiendo
Saludos
Mario Mansilla
- Attachments
-
- IP.rar
- (8.99 KiB) Downloaded 229 times
Re: IP Publica
Bueno, despues de todo no fué tan dificil...
----------------------------------------------------------
Well, after all it was not so difficult ...
----------------------------------------------------------
Well, after all it was not so difficult ...
Code: Select all
#include <hmg.ch>
Function Main
LOCAL cURL := "https://api.ipify.org/?format=json"
DEFINE WINDOW Main AT 138 , 235 WIDTH 550 HEIGHT 350
@ 070,160 LABEL Label_1 OF Main VALUE "" WIDTH 200 HEIGHT 25 FONT "Consolas" SIZE 14 ;
FONTCOLOR { 70, 130, 180 } BACKCOLOR { 210, 233, 255 } BORDER CENTERALIGN
Main.Label_1.Value := SaveURL( cURL )
END WINDOW
Main.CENTER
Main.ACTIVATE
Return nil
Function SaveURL( cUrl )
LOCAL cTmpFile := "x.htm", cHtml
IF URLDownloadToFile( cUrl, cTmpFile)
cHtml := HB_MemoRead( cTmpFile )
cHtml := STRTRAN( cHtml, "{", "" )
cHtml := STRTRAN( cHtml, "}", "" )
cHtml := STRTRAN( cHtml, '"', "" )
ENDIF
Return cHtml
#pragma BEGINDUMP
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"
#include <Windows.h>
#include <urlmon.h>
#include "hbapi.h"
HB_FUNC( URLDOWNLOADTOFILE )
{
HRESULT hr = URLDownloadToFile(NULL, HMG_parc(1), HMG_parc(2), 0, NULL);
hb_retl(hr == S_OK);
}
#pragma ENDDUMP
Andrés González López
Desde Guadalajara, Jalisco. México.
Desde Guadalajara, Jalisco. México.
Re: IP Publica
Code: Select all
//bpd2000
#include "hmg.ch"
Function Main()
msginfo( ExternalIP(),"External IP Address"+space(10))
Return
Function ExternalIP()
Local cApiUrl := "http://checkip.dyndns.com/"
LOCAL nStart, nLen
oGoogle := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" )
BEGIN SEQUENCE WITH {|o| break(o)}
oGoogle:Open( "GET", cApiUrl, .F. )
oGoogle:SEND()
cGoogleResp := oGoogle:ResponseBody()
Ext_IP := HB_AtX( "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", cGoogleResp, .F., @nStart, @nLen )
IF oGoogle:Status != 200
BREAK
ENDIF
RECOVER
MsgStop("ERROR! ")
RETURN nil
END SEQUENCE
oGoogle:Abort()
RETURN Ext_IP
BPD
Convert Dream into Reality through HMG
Convert Dream into Reality through HMG
-
- Posts: 269
- Joined: Wed Aug 13, 2008 2:35 pm
- Location: Córdoba - Argentina
Re: IP Publica
Hola Amigos :
ahora ya tengo varias opciones .
Muchas gracias a todos
Saludos cordiales
Mario Mansilla
Hello friends :
Now I have several options.
Thank you very much to all
Best regards
Mario Mansilla
ahora ya tengo varias opciones .
Muchas gracias a todos
Saludos cordiales
Mario Mansilla
Hello friends :
Now I have several options.
Thank you very much to all
Best regards
Mario Mansilla
- AUGE_OHR
- Posts: 2062
- Joined: Sun Aug 25, 2019 3:12 pm
- DBs Used: DBF, PostgreSQL, MySQL, SQLite
- Location: Hamburg, Germany
Re: IP Publica
hi,
but i don´t understand Error as HB_FUNC is include and it have "A" and "W" of "URLDownloadToFile"
https://docs.microsoft.com/en-us/previo ... dfrom=MSDN
what do i make wrong
i have try Sample but i got Errprandyglezl wrote: ↑Tue Jul 03, 2018 5:07 amCode: Select all
HB_FUNC( URLDOWNLOADTOFILE ) { HRESULT hr = URLDownloadToFile(NULL, HMG_parc(1), HMG_parc(2), 0, NULL);
! Note i use Unicode Versionundefined reference to `URLDownloadToFileW'
but i don´t understand Error as HB_FUNC is include and it have "A" and "W" of "URLDownloadToFile"
https://docs.microsoft.com/en-us/previo ... dfrom=MSDN
what do i make wrong
have fun
Jimmy
Jimmy
Re: IP Publica
AUGE_OHR wrote: ↑Fri Nov 12, 2021 3:01 am hi,i have try Sample but i got Errprandyglezl wrote: ↑Tue Jul 03, 2018 5:07 amCode: Select all
HB_FUNC( URLDOWNLOADTOFILE ) { HRESULT hr = URLDownloadToFile(NULL, HMG_parc(1), HMG_parc(2), 0, NULL);
! Note i use Unicode Versionundefined reference to `URLDownloadToFileW'
but i don´t understand Error as HB_FUNC is include and it have "A" and "W" of "URLDownloadToFile"
https://docs.microsoft.com/en-us/previo ... dfrom=MSDN
what do i make wrong
Incluiste el archivo MainIPPub.hbp ?
Hace rato lo probé y funcionó.
*------------------------------------------------
Did you include the MainIPPub.hbp file?
I tried it a while ago and it worked.
Andrés González López
Desde Guadalajara, Jalisco. México.
Desde Guadalajara, Jalisco. México.