Jump to content
Fivewin Brasil

Descobrir o IP do PC


Rogerio Figueira

Recommended Posts

Amigo Rogério...

Veja se isso te ajuda.

/****************************************************************/
// Rotinas para pegar as Configurações de rede By Vagner Wirts  //
/****************************************************************/

#include "fivewin.ch"


//positions inside array returned by GetNetCardInfo()

#define ADP_NAME        1  //An ANSI character string of the name of the adapter. (STRING)
#define ADP_DESCRIPTION 2  //An ANSI character string that contains the description 
                           //of the adapter. (STRING)
#define ADP_ADDRESS     3  //The hardware address for the adapter (STRING)
#define ADP_INDEX       4  //The adapter index. 
                           //The adapter index may change when an adapter is disabled 
                           //and then enabled, or under other circumstances, 
                           //and should not be considered persistent.(NUMERIC)
#define ADP_TYPE        5  //The adapter type. see define list type (bellow) (NUMERIC)
#define ADP_DHCPENABLED 6  //An option value that specifies whether the dynamic host 
                           //configuration protocol (DHCP) is enabled for this adapter.(LOGICAL)
                           
#define ADP_ADDRESSLIST 7  //The list of IPv4 addresses associated with this adapter(STRING)
#define ADP_GATEWAY     8  //The IPv4 address of the gateway for this adapter (STRING)
#define ADP_DHCPSERVER  9  //The IPv4 address of the DHCP server for this adapter represented(STRING)
#define ADP_HAVEWINS    10 //An option value that specifies whether this adapter uses (LOGICAL)
                           //the Windows Internet Name Service (WINS).(LOGICAL)
#define ADP_PRIMARY     11 //the IPv4 address of the primary WINS server
#define ADP_SECUNDARY   12 //The IPv4 address of the secondary WINS server


//Types
#define MIB_IF_TYPE_OTHER      1 //Some other type of network interface.
#define MIB_IF_TYPE_ETHERNET   6 //An Ethernet network interface.
#define MIB_IF_TYPE_TOKENRING  9
#define MIB_IF_TYPE_PPP       23 //A PPP network interface.
#define MIB_IF_TYPE_LOOPBACK  24 //A software loopback network interface.
#define MIB_IF_TYPE_SLIP      28 //An ATM network interface.
#define IF_TYPE_IEEE80211     71 //An IEEE 802.11 wireless network interface.
                                 //Note  This adapter type is returned on Windows Vista and later. 
                                 //On Windows Server 2003 and Windows XP , 
                                 //an IEEE 802.11 wireless network interface returns an adapter 
                                 //type of MIB_IF_TYPE_ETHERNET.


//---------------------------------------------------//
FUNCTION TESTEMAC()
Local aConec, lOk:=.T.
Local lAchouWiFi := .F.
Local lAchouRede := .F.
Local i:=1

aConec := GetNetCardInfo()

aEval(aConec,<|aCon,nPos|

   If "WI-FI" $ Upper(aCon[2]) .or. "WIRELES" $ Upper(aCon[2]) .or. "BLUETOOTH" $ Upper(aCon[2]) .or. "HOSTED" $ Upper(aCon[2]) .or. "TeamViewer" $ Upper(aCon[2]) .or. "VPN" $ Upper(aCon[2]) .or. "TAP" $ Upper(aCon[2])
      lAchouWiFi := .T.
   Else
       If Empty(VAL(aCon[7])) .AND. EMPTY(VAL(aCon[9]))
          lTemp:=.F.
		  lOk:=.F.
          MsgStop("Nao foi Detectada a Conexao Ethernet da Rede Com o Servidor...","ATENCAO...")
       Else
          lAchouRede := .T.
       Endif
   Endif

>)

    ? "Rede Interna : "+Iif(lAchouRede,""," Não")+ " Achou",;
      "Wi-Fi        : "+Iif(lAchouWiFi,""," Não")+ " Achou",;

xbrowse( GetNetCardInfo() )

return nil

//--------------- FIM DO PROGRAMA ------------------------//

Essa Rotina foi criada pelo Mestre Vagner Wirts.

Ela pega as informações da rede.

Repare que nas colunas G,H e I estão as informações dos Ips e Getway.

Acredito que você deve usar as informações das Colunas H ou I.

Abraços.

 

 

Link to comment
Share on other sites

Olá  pessoal,
obrigado pelas contribuições.

Eu ainda não tive tempo de testar a solução passada pelo Valdir nem a Pinga do Rochinha.

Tentei agora a solução do  Sistem , que parece a mais simples de implementar, mas apresenta um erro, não tenho a função WebConnect:
Unresolved external '_HB_FUN_WEBCONNECT'

Eu utilizo o FiveWin  1402  e o xHarbour 1.2.3 .

[]´s

 

Link to comment
Share on other sites

Pessoal, quero agradecer a colaboração de todos e postar aqui a solução baseada na dica do Rochinha e outra que descobri na documentação do MySQL.

Desta forma eu pego o IP do cliente da última conexão ao banco MySQL, isto é, conecto ao banco de dados e logo a seguir executo esta verificação:

   TRY
      CONNECT bServer HOST alltrim(host) ;
                      USER alltrim(usuario) ;
                      PASSWORD alltrim(senha) ;
                      PORT nPort ;
                      FLAGS nFlags;
                      DATABASE "information_schema"                               
   CATCH oErr     
    MsgInfo( oErr:Description )

     RETURN NIL
   END
   oQry:= bServer:Query("SELECT host FROM information_schema.processlist  WHERE ID = connection_id( ) LIMIT 0 , 10")  
   userIP := oQry:host

bServer:end()

//=========================================
Aqui usando a dica do Rochinha a partir do código do PINGA:


#include "dll.ch"

static xdll


CLASS TdWebService

  DATA hOpen

  DATA sbuffer HIDDEN

  DATA xDLL HIDDEN

  METHOD New(buffersize) CONSTRUCTOR

  METHOD OpenWS(url)

  METHOD End()

ENDCLASS


METHOD New(conexion,buffersize) CLASS TdWebService

 DEFAULT buffersize:=64000

 ::sbuffer:=buffersize

 xDll:=LoadLib32("wininet.dll")

 ::hOpen = InternetOpen("TdWebService", 1,,, 0)

 RETURN Self


METHOD OpenWS(url) CLASS TdWebService

 local hFile,ret,xml

 hFile = InternetOpenUrl(::hOpen, url,"",0,,0)

 xml:=space(::sbuffer)

 InternetReadFile(hFile, @xml, ::sbuffer, @Ret)

 return alltrim(xml)

 //return subst(alltrim(xml),1,len(alltrim(xml))-5)


METHOD End() CLASS TdWebService

 FreeLib32(xDll)

 return nil
 
 
 Dll32 FUNCTION InternetOpenUrl(hInternetSession As 7, lpszUrl As 8, lpszHeaders As 8, dwHeadersLength As 7, dwFlags As 7, dwContext As 7) As 7 FROM "InternetOpenUrlA" PASCAL Lib xDll
 
 Dll32 FUNCTION InternetReadFile(hFile As 7, @sBuffer As 8, lNumBytesToRead As 7, @lNumberOfBytesRead As 7) As 7 PASCAL Lib xDll

//==========================

function getIPExtern( _site_ )

 local _IPExtern_

 ws:=TdWebService():new()

 _IPExtern_ := ws:OpenWS(_site_)

 ws:end()

msginfo(_IPExtern_)
 return
 
 //===========================
 
  getIPExtern("http://representantes.info/meuip.php")

//=========================
Conforme a dica do Sistem acima,  o código do arquivo meuip.php  é este:
<?php $ip = getenv("REMOTE_ADDR");echo "$ip" ?>

//=============================

Sds.

 

 

 

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...