elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Recuperar la IP Publica
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Recuperar la IP Publica  (Leído 2,945 veces)
LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 760


www.leandroascierto.com


Ver Perfil WWW
Recuperar la IP Publica
« en: 2 Agosto 2007, 18:06 pm »

Buenas se que quienes tienen Router el winsock no devuelve la ip publica, yo en mi caso como no tengo router no se como hacerlo, pero me gustaria saver como se puede conseguir la ip publica sin tener que recurrir a una web. (estoy ablando de hacerlo por codigo)

bien un amigo me paso este ejemplo

Código:
'In Module1:

'******************************************************************
'Created By Verburgh Peter.
' 07-23-2001
' verburgh.peter@skynet.be
'-------------------------------------
'With this small application , you can detect the IP's installed on your computer,
'including subnet mask , BroadcastAddr..
'
'I've wrote this because i've a programm that uses the winsock control, but,
'if you have multiple ip's  installed on your pc , you could get by using the Listen
' method the wrong ip ...
'Because Winsock.Localip => detects the default ip installed on your PC ,
' and in most of the cases it could be the LAN (nic) not the WAN (nic)
'So then you have to use the Bind function ,to bind to your right ip..
'but how do you know & find that ip ?
'you can find it now by this appl.. it check's in the api.. IP Table..
'******************************************************************


Const MAX_IP = 5   'To make a buffer... i dont think you have more than 5 ip on your pc..

Type IPINFO
     dwAddr As Long   ' IP address
    dwIndex As Long '  interface index
    dwMask As Long ' subnet mask
    dwBCastAddr As Long ' broadcast address
    dwReasmSize  As Long ' assembly size
    unused1 As Integer ' not currently used
    unused2 As Integer '; not currently used
End Type

Type MIB_IPADDRTABLE
    dEntrys As Long   'number of entries in the table
    mIPInfo(MAX_IP) As IPINFO  'array of IP address entries
End Type

Type IP_Array
    mBuffer As MIB_IPADDRTABLE
    BufferLen As Long
End Type

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As Long, ByVal Sort As Long) As Long
Sub main()
Form1.Show
End Sub

'converts a Long  to a string
Public Function ConvertAddressToString(longAddr As Long) As String
    Dim myByte(3) As Byte
    Dim Cnt As Long
    CopyMemory myByte(0), longAddr, 4
    For Cnt = 0 To 3
        ConvertAddressToString = ConvertAddressToString + CStr(myByte(Cnt)) + "."
    Next Cnt
    ConvertAddressToString = Left$(ConvertAddressToString, Len(ConvertAddressToString) - 1)
End Function

Public Sub Start()
Dim Ret As Long, Tel As Long
Dim bBytes() As Byte
Dim Listing As MIB_IPADDRTABLE



On Error GoTo END1
    GetIpAddrTable ByVal 0&, Ret, True

    If Ret <= 0 Then Exit Sub
    ReDim bBytes(0 To Ret - 1) As Byte
    'retrieve the data
    GetIpAddrTable bBytes(0), Ret, False
     
    'Get the first 4 bytes to get the entry's.. ip installed
    CopyMemory Listing.dEntrys, bBytes(0), 4
    'MsgBox "IP's found : " & Listing.dEntrys    => Founded ip installed on your PC..
    Form1.AutoRedraw = True
    Form1.Print Listing.dEntrys & "   IP addresses found on your PC !!"
    Form1.Print "----------------------------------------"
    For Tel = 0 To Listing.dEntrys - 1
        'Copy whole structure to Listing..
       ' MsgBox bBytes(tel) & "."
        CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))
         Form1.Print "IP address                   : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr)
         Form1.Print "IP Subnetmask            : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwMask)
         Form1.Print "BroadCast IP address  : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwBCastAddr)
         Form1.Print "**************************************" & vbCrLf
         Form1.Refresh
    Next

'MsgBox ConvertAddressToString(Listing.mIPInfo(1).dwAddr)
Exit Sub
END1:
MsgBox "ERROR"
End Sub

Código:
Private Sub Form_Load()
Module1.Start
End Sub

en su caso le aparecio en la tercera posicion su ip publica
alguno de los que tengan un router se anima a ver si puede obtener unicamente esa ip

Gracias y saludos

aca hay otro codigo parecido, aver si este muestra la ip publica
http://www.recursosvisualbasic.com.ar/htm/listado-api/api-55-ip-GetIpAddrTable.htm


En línea

Freeze.


Desconectado Desconectado

Mensajes: 2.732



Ver Perfil WWW
Re: Recuperar la IP Publica
« Respuesta #1 en: 2 Agosto 2007, 21:12 pm »

Con los sockets...

Puede ser con la API o con el control Winsock...

Muy Facil...


En línea

LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 760


www.leandroascierto.com


Ver Perfil WWW
Re: Recuperar la IP Publica
« Respuesta #2 en: 2 Agosto 2007, 21:43 pm »

no no noes facil creo que no me entendiste, no dije ip privada dije IP ""PUBLICA"", se que este codigo lo tira pero me tira otras ip mas el tema es aislar es ip publica y como no tengo router para provar no se como hacerlo esdecir mi ip privada y mi ip publica son iguales.
En línea

~~
Ex-Staff
*
Desconectado Desconectado

Mensajes: 2.981


Ver Perfil WWW
Re: Recuperar la IP Publica
« Respuesta #3 en: 2 Agosto 2007, 22:00 pm »

No, no funciona, el primer codigo te muestra la ip local y la loop ip (12.0.0.1) vamos q un ipconfig /all es mas completo q todo eso...
El segundo cogigo tampoco funciona, te debuelve la local...

Creo q lo mejor q puedes hacer es contactar con alguna web tipo cualesmiip.com y leer lo q te devuelve..
En línea

Mad Antrax
Colaborador
***
Desconectado Desconectado

Mensajes: 2.164


Cheats y Trainers para todos!


Ver Perfil WWW
Re: Recuperar la IP Publica
« Respuesta #4 en: 2 Agosto 2007, 23:52 pm »

Aquí el source, solo necesitas agregar el control MSWinsck o en su defecto el CSocketMaster:

Código
  1. Private Sub Command1_Click()
  2.    Label1.Caption = "Cerrando conexión..."
  3.    WS.Close
  4.    DoEvents
  5.    WS.Connect "checkip.dyndns.org", 80
  6.    Label1.Caption = "Conectando..."
  7.    DoEvents
  8. End Sub
  9.  
  10. Private Sub WS_Connect()
  11.    Label1.Caption = "Conectado!"
  12.    WS.SendData "GET / HTTP/1.1" & vbCrLf & vbCrLf
  13. End Sub
  14.  
  15. Private Sub WS_DataArrival(ByVal bytesTotal As Long)
  16.    Dim Buffer As String
  17.    Dim Datos() As String
  18.  
  19.    WS.GetData Buffer, vbString
  20.    If InStr(Buffer, "Current IP") <> 0 Then
  21.        Datos = Split(Buffer, "<")
  22.        Datos = Split(Datos(6), ":")
  23.        Label1.Caption = Trim(Datos(1))
  24.    Else
  25.        Label1.Caption = "IP no encontrada"
  26.    End If
  27. End Sub
  28.  
  29. Private Sub WS_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  30.    On Error Resume Next
  31.    Label1.Caption = "Error!"
  32.    MsgBox Number & " - " & Description
  33. End Sub
  34.  

El código es de lo más simple, se conecta a la web checkip.dyndns.org y manda un GET al index, explora el código que devuelve el webserver para mostrar tan solo la IP pública. Es un método que no me gusta porque en el momento que checkip.dyndns.org deje de funcionar o cambie el formato se jodió nuestro código.

El código no es mío, alguien de este foro me lo pasó hace bastante tiempo por MP y no recuerdo el nombre, sorry.
En línea

No hago hacks/cheats para juegos Online.
Tampoco ayudo a nadie a realizar hacks/cheats para juegos Online.
LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 760


www.leandroascierto.com


Ver Perfil WWW
Re: Recuperar la IP Publica
« Respuesta #5 en: 3 Agosto 2007, 04:03 am »

Gracias pero es raro tiene que aver alguna forma de obtenerlo sin nesidad de hacer una peticion web , osea si ipconfig /all te la devuelve  tiene que aver una forma no?

a la ip publica es a la que le llaman ip wan?


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda necesito recuperar una pagina publica que administraba en facebook
Dudas Generales
ma666 2 7,550 Último mensaje 2 Septiembre 2011, 03:18 am
por .:UND3R:.
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines