IP Publica

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Mario Mansilla
Posts: 269
Joined: Wed Aug 13, 2008 2:35 pm
Location: Córdoba - Argentina

IP Publica

Post by Mario Mansilla »

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
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: IP Publica

Post by andyglezl »

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
Andrés González López
Desde Guadalajara, Jalisco. México.
jayadevu
Posts: 238
Joined: Tue May 19, 2009 7:10 am

Re: IP Publica

Post by jayadevu »

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
jayadevu
Posts: 238
Joined: Tue May 19, 2009 7:10 am

Re: IP Publica

Post by jayadevu »

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
Mario Mansilla
Posts: 269
Joined: Wed Aug 13, 2008 2:35 pm
Location: Córdoba - Argentina

Re: IP Publica

Post by Mario Mansilla »

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
Attachments
IP.rar
(8.99 KiB) Downloaded 220 times
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: IP Publica

Post by andyglezl »

Bueno, despues de todo no fué tan dificil...
----------------------------------------------------------
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
MainIPPub.rar
(819 Bytes) Downloaded 251 times
ippub.png
ippub.png (4.33 KiB) Viewed 4998 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: IP Publica

Post by bpd2000 »

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
Mario Mansilla
Posts: 269
Joined: Wed Aug 13, 2008 2:35 pm
Location: Córdoba - Argentina

Re: IP Publica

Post by Mario Mansilla »

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
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: IP Publica

Post by AUGE_OHR »

hi,
andyglezl wrote: Tue Jul 03, 2018 5:07 am

Code: Select all

HB_FUNC( URLDOWNLOADTOFILE )
{
  HRESULT hr = URLDownloadToFile(NULL, HMG_parc(1), HMG_parc(2), 0, NULL);
i have try Sample but i got Errpr
undefined reference to `URLDownloadToFileW'
! Note i use Unicode Version

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
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: IP Publica

Post by andyglezl »

AUGE_OHR wrote: Fri Nov 12, 2021 3:01 am hi,
andyglezl wrote: Tue Jul 03, 2018 5:07 am

Code: Select all

HB_FUNC( URLDOWNLOADTOFILE )
{
  HRESULT hr = URLDownloadToFile(NULL, HMG_parc(1), HMG_parc(2), 0, NULL);
i have try Sample but i got Errpr
undefined reference to `URLDownloadToFileW'
! Note i use Unicode Version

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.
imagen_2021-11-11_225745.png
imagen_2021-11-11_225745.png (39.91 KiB) Viewed 1425 times
Andrés González López
Desde Guadalajara, Jalisco. México.
Post Reply