Saber Ip Publico

Saber Ip Publico

Postby Busmatic_wpb » Fri Dec 07, 2018 2:12 am

Estimados compadres, saludes a la distancia y apeticion de una listero publicamos la rutina en C para saber cual en el IP Externo.\
el Señor Alberto Valencia de Venezuela nos autorizo a su publicacion.

/*
Autor : Albeiro Valencia
: IP externo
Fecha : 30/07/2018
Todos los derechos reservados
albeiroval@gmail.com

Se llama asi..
IpExterna:=IPPUBLIC()
*/

#include <stdio.h>
#include <urlmon.h>
#include <WinInet.h>

#include "hbapi.h"

#pragma comment(lib, "urlmon.lib")

//-----------------------------------//

char *GetIP();
bool IsLanOrModem();

//-----------------------------------//

HB_FUNC( IPPUBLIC )
{
char *pszChar = "";

strcpy( pszChar, GetIP() );

hb_retc( pszChar );
}

//-----------------------------------//

char *GetIP()
{
char szPath[256], szRead[128], szRet[256];
char szSite[] = "http://checkip.dyndns.org/Current IP Check.htm";
char *Token;
char *cRet;

memset(szPath,0,sizeof(szPath));
memset(szRet,0,sizeof(szRet));

GetTempPath(256, szPath);
strcat(szPath, "my_ip.txt");

if( URLDownloadToFile(0, szSite, szPath, 0, 0) == S_OK )
{
FILE *fIpHtm = fopen(szPath, "r");
if( fIpHtm )
{
fgets(szRead, 128, fIpHtm);
Token = strrchr(szRead, ':');
Token = strtok(Token, "<");
memcpy(szRead, Token + 2, sizeof(szRead));
strcpy(cRet, szRead);

return cRet;
}
else
{
return "Error.";
}
}
else
return "Error.";
}

//-----------------------------------//

HB_FUNC( ISLANCONEXION )
{
hb_retl( IsLanOrModem() );
}

//-----------------------------------//

bool IsLanOrModem()
{
DWORD result;

if (!InternetGetConnectedState(&result, 0))
return false;

return result & INTERNET_CONNECTION_LAN || result & INTERNET_CONNECTION_MODEM;
}

// FINAL
Regards.
S.I.T.U.
Sistemas Inteligentes de transporte urbano
http://www.situcr.com
oscarchacon@Situcr.com
Desarrollos BA4/B4j androide
User avatar
Busmatic_wpb
 
Posts: 162
Joined: Wed Feb 22, 2017 2:19 am

Tambien Saber Ip LOCAL

Postby Busmatic_wpb » Fri Dec 07, 2018 2:15 am

/*
File : iplocal.cpp
Autor : Albeiro Valencia
Fecha : 30/07/2018
Todos los derechos reservados
albeiroval@gmail.com

Se llama asi..
IpLocal =:IPLOCAL()

*/

#include <Windows.h>
#include <WinSock.h>
#include <hbapi.h>

HB_FUNC( IPLOCAL )
{
WSADATA wsa_Data;

WSAStartup( 0x101, &wsa_Data );

char szHostName[255];
gethostname(szHostName, 255);

struct hostent *host_entry;
host_entry = gethostbyname(szHostName);

char * szLocalIP;
szLocalIP = inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list);

WSACleanup();

hb_retc( szLocalIP );
}

// FINAL
Regards.
S.I.T.U.
Sistemas Inteligentes de transporte urbano
http://www.situcr.com
oscarchacon@Situcr.com
Desarrollos BA4/B4j androide
User avatar
Busmatic_wpb
 
Posts: 162
Joined: Wed Feb 22, 2017 2:19 am


Return to FiveWin para Harbour/xHarbour

Who is online

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