IP Publica
Moderator: Rathinagiri
-
- Posts: 246
- Joined: Wed Aug 13, 2008 2:35 pm
- Location: Córdoba - Argentina
- Been thanked: 2 times
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
- andyglezl
- Posts: 1089
- Joined: Fri Oct 26, 2012 7:58 pm
- Location: Guadalajara Jalisco, MX
- Has thanked: 26 times
- Been thanked: 61 times
- Contact:
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.
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
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: 246
- Joined: Wed Aug 13, 2008 2:35 pm
- Location: Córdoba - Argentina
- Been thanked: 2 times
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 40 times
- andyglezl
- Posts: 1089
- Joined: Fri Oct 26, 2012 7:58 pm
- Location: Guadalajara Jalisco, MX
- Has thanked: 26 times
- Been thanked: 61 times
- Contact:
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.
- bpd2000
- Posts: 1045
- Joined: Sat Sep 10, 2011 4:07 am
- Location: India
- Has thanked: 180 times
- Been thanked: 85 times
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: 246
- Joined: Wed Aug 13, 2008 2:35 pm
- Location: Córdoba - Argentina
- Been thanked: 2 times
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