Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: 4D1cTo en 29 Enero 2006, 06:55 am



Título: mostrar ip local
Publicado por: 4D1cTo en 29 Enero 2006, 06:55 am
solo quiero saber como hacer un form donde presionando un boton me muestre la ip local...

es algo muy sencillo me imagino pero soy nw en esto de la programacion :$


Título: Re: mostrar ip local
Publicado por: #Borracho.- en 29 Enero 2006, 07:17 am
Con el comando LocalIp.

Saludos


Título: Re: mostrar ip local
Publicado por: #Borracho.- en 29 Enero 2006, 07:18 am
Si no me equivoco, era algo asi...

Código:
Private Sub Form_Load()
Label1.caption = WinSock1.LocalIP
End Sub


Título: Re: mostrar ip local
Publicado por: 4D1cTo en 30 Enero 2006, 00:33 am
me proboca error :S


Título: Re: mostrar ip local
Publicado por: ciruit en 30 Enero 2006, 05:02 am
Emmm es que si no tienes un un form llamado form1, ni un label llamado label1 ni un winsock llamado winsock1 no te va a funcionar.


Título: Re: mostrar ip local
Publicado por: sorcerer en 30 Enero 2006, 13:24 pm
que error te da?


Título: Re: mostrar ip local
Publicado por: #Borracho.- en 30 Enero 2006, 14:18 pm
Emmm es que si no tienes un un form llamado form1, ni un label llamado label1 ni un winsock llamado winsock1 no te va a funcionar.

Es verdad, pensé que te ivas a dar cuenta. Igual pone el error

Saludos


Título: Re: mostrar ip local
Publicado por: Meg en 30 Enero 2006, 14:29 pm
primero tienes k poner un label con el nombre de label1 k ya viene por defecto y luego agregar el control winsock.Para agregar el winsock tienes k pinchar arriba del todo en proyecto y luego en componentes buscas el Microsoft winsock control lo seleccionas y le das a aceptar luego pones el winsock en el formulario y utilizas el codigo de JeRoS


Título: Re: mostrar ip local
Publicado por: {_The_Alwar_} en 30 Enero 2006, 20:40 pm
y como se podria hacer para mostrar la ip q usas fuera de tu red logica?


Título: Re: mostrar ip local
Publicado por: #Borracho.- en 31 Enero 2006, 14:35 pm
Como :huh:

Saludos


Título: Re: mostrar ip local
Publicado por: Kizar en 31 Enero 2006, 15:10 pm
Y sin usar el control winsock como podria conocer mi ip, es k con las apis estuve mirando y son codes muy largos para algo tan sencillo....

Salu2


Título: Re: mostrar ip local
Publicado por: {_The_Alwar_} en 31 Enero 2006, 16:41 pm
haber, en tu lan (tu red logica y fisica) tienes una ip, que suele ser 192.168.0.x el router tiene 192.168.0.1 pero si alguien desde internet se quiere conectar a tu ordenador a de saber la ip externa, la que utilizas de cara a internet, como puedo averiguar esa ip? supongo que el winsock no puede averiguarla ya que esta en el router que es como otro ordenador, por tanto tendria que preguntarsela al router, pero no se como


Título: Re: mostrar ip local
Publicado por: #Borracho.- en 31 Enero 2006, 22:08 pm
Pero para eso ya tendría que haber un programa en tu pc y otro en el router... O si no si está conectado con vos... Con shell que se fije el netstat y te diga la ip del router que vos queres saber.

No es asi?
Saludos


Título: Re: mostrar ip local
Publicado por: BenRu en 31 Enero 2006, 22:40 pm
Y sin usar el control winsock como podria conocer mi ip, es k con las apis estuve mirando y son codes muy largos para algo tan sencillo....

Salu2

Pues utiliza el emulador, socketmaster o algo asi verdad?
Busca info en el foro


Título: Re: mostrar ip local
Publicado por: {_The_Alwar_} en 31 Enero 2006, 22:54 pm
nose, digo yo q se le podra enviar algun comando al router y que te devuelva datos, en linux seria facil, haces un traceroute y con el grep cojes la segunda ip, en windows no se como pueda filtrar la salida estandar que de tracert


Título: Re: mostrar ip local
Publicado por: Kizar en 1 Febrero 2006, 22:16 pm
ya usaba el socketmaster peor este pones ws.localIP y no te muestra nada  :P

Salu2


Título: Re: mostrar ip local
Publicado por: scod en 2 Febrero 2006, 06:04 am
 no puedes conocer la ip publica de tu red desde el winsock u otra clase que emule a este control por medio del .localip, tendrias que usar el winsock, y conectarte a una pagina  de esas que te dicen la ip, osea todo por medio de http, capturas los priemros datos que te mandan,.. me explico,..

por ejemplo en la pagina http://whatsmyip.org/ te da tu ip publica, lo que tendrias que hacer es conectarte a esta page y buscar entre el code html las palabras "Your IP Address is" y luego sacar la infoq ue sigue, que seria tu ip,.. me explique? :p

y bue, pa sacar la ip local sin el winsock puedes usar este code que encontre hace mucho,...

Código:
Option Explicit
Private Const MAX_WSADescription = 256
Private Const MAX_WSASYSStatus = 128
Private Const ERROR_SUCCESS As Long = 0
Private Const WS_VERSION_REQD As Long = &H101
Private Const WS_VERSION_MAJOR As Long = WS_VERSION_REQD  &H100 And &HFF&
Private Const WS_VERSION_MINOR As Long = WS_VERSION_REQD And &HFF&
Private Const MIN_SOCKETS_REQD As Long = 1
Private Const SOCKET_ERROR As Long = -1
Private Type HOSTENT
    hName As Long
    hAliases As Long
    hAddrType As Integer
    hLen As Integer
    hAddrList As Long
    End Type
Private Type WSADATA
    wVersion As Integer
    wHighVersion As Integer
    szDescription(0 To MAX_WSADescription) As Byte
    szSystemStatus(0 To MAX_WSASYSStatus) As Byte
    wMaxSockets As Integer
    wMaxUDPDG As Integer
    dwVendorInfo As Long
    End Type
Private Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long
Private Declare Function WSAStartup Lib "WSOCK32.DLL" _
    (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long
Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Private Declare Function GetHostName Lib "WSOCK32.DLL" _
    Alias "gethostname" (ByVal szHost As String, ByVal dwHostLen As Long) As Long
Private Declare Function gethostbyname Lib "WSOCK32.DLL" _
    (ByVal szHost As String) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Public Function GetLocalHost() As String
    Dim sHostName As String * 256
    If Not SocketsInitialize() Then
        GetLocalHost = ""
        Exit Function
    End If
    If GetHostName(sHostName, 256) = SOCKET_ERROR Then
        GetLocalHost = ""
''        MsgBox "Windows Sockets Error " & str$(WSAGetLastError()) & _
''        " has occurred. Unable To successfully Get Host Name."
        SocketsCleanup
        Exit Function
    End If
    GetLocalHost = Left$(sHostName, InStr(sHostName, Chr(0)) - 1)
    SocketsCleanup
End Function

Public Function GetLocalIP() As String
    Dim sHostName As String * 256
    Dim lpHost As Long
    Dim HOST As HOSTENT
    Dim dwIPAddr As Long
    Dim tmpIPAddr() As Byte
    Dim i As Integer
    Dim sIPAddr As String
    If Not SocketsInitialize() Then
        GetLocalIP = ""
        Exit Function
    End If
    If GetHostName(sHostName, 256) = SOCKET_ERROR Then
        GetLocalIP = ""
''        MsgBox "Windows Sockets Error " & Str$(WSAGetLastError()) & _
''        " has occurred. Unable To successfully Get Host Name."
        SocketsCleanup
        Exit Function
    End If
    sHostName = Trim$(sHostName)
    lpHost = gethostbyname(sHostName)
    If lpHost = 0 Then
        GetLocalIP = ""
''        MsgBox "Windows Sockets are Not responding. " & _
''        "Unable To successfully Get Host Name."
        SocketsCleanup
        Exit Function
    End If
    CopyMemory HOST, lpHost, Len(HOST)
    CopyMemory dwIPAddr, HOST.hAddrList, 4
    ReDim tmpIPAddr(1 To HOST.hLen)
    CopyMemory tmpIPAddr(1), dwIPAddr, HOST.hLen
    For i = 1 To HOST.hLen
        sIPAddr = sIPAddr & tmpIPAddr(i) & "."
    Next
    GetLocalIP = Mid$(sIPAddr, 1, Len(sIPAddr) - 1)
    SocketsCleanup
End Function
Private Function HiByte(ByVal wParam As Integer)
    HiByte = wParam  &H100 And &HFF&
   
End Function
Private Function LoByte(ByVal wParam As Integer)
    LoByte = wParam And &HFF&
End Function
Private Sub SocketsCleanup()
    If WSACleanup() <> ERROR_SUCCESS Then
        MsgBox "Socket Error occurred In Cleanup."
    End If
End Sub
Private Function SocketsInitialize() As Boolean
    Dim WSAD As WSADATA
    Dim sLoByte As String
    Dim sHiByte As String
    If WSAStartup(WS_VERSION_REQD, WSAD) <> ERROR_SUCCESS Then
        MsgBox "The 32-bit Windows Socket is Not responding."
        SocketsInitialize = False
        Exit Function
    End If
    If WSAD.wMaxSockets < MIN_SOCKETS_REQD Then
        MsgBox "This application requires a minimum of " & _
        CStr(MIN_SOCKETS_REQD) & " supported sockets."
        SocketsInitialize = False
        Exit Function
    End If
    If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or _
    (LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And _
    HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
   
    sHiByte = CStr(HiByte(WSAD.wVersion))
    sLoByte = CStr(LoByte(WSAD.wVersion))
   
    MsgBox "Sockets version " & sLoByte & "." & sHiByte & _
    " is Not supported by 32-bit Windows Sockets."
   
    SocketsInitialize = False
    Exit Function
   
End If
SocketsInitialize = True
End Function

que como puedes ver hay dos funciones que rtetornan la ip local y el nombre del host local o nombre de red

saludos


Título: Re: mostrar ip local
Publicado por: #Borracho.- en 2 Febrero 2006, 12:50 pm
son codes muy largos para algo tan sencillo....

Si, es muy largo el code aunque es una buena opción y funcional. Alguien sabe de otra mas corta y funcional?

Saludos


Título: Re: mostrar ip local
Publicado por: Kizar en 2 Febrero 2006, 15:05 pm
Lo k encontre yo, pero no es mas corto...

Muestra todas las ips de un ekipo.
FUENTE: Api-Guide

Citar
Private Sub Command1_Click()
    Module1.Start
End Sub

''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

Form1.Text1 = ""

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.Text1 = Listing.dEntrys & "   IP addresses found on your PC !!" & vbCrLf
    Form1.Text1 = Form1.Text1 & "----------------------------------------" & vbCrLf
    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.Text1 = Form1.Text1 & "IP address                   : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr) & vbCrLf
         Form1.Text1 = Form1.Text1 & "IP Subnetmask            : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwMask) & vbCrLf
         Form1.Text1 = Form1.Text1 & "BroadCast IP address  : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwBCastAddr) & vbCrLf
         Form1.Text1 = Form1.Text1 & "**************************************" & vbCrLf
    Next

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

Salu2


Título: Re: mostrar ip local
Publicado por: Ar_mx en 4 Abril 2006, 16:10 pm
Insserta un label, un command y un winsock
en el command codifica asì:
private sub command1_click()
label1=winsock1.localip
end sub
----------------------------------------------
solamente, espero que te funcione
saludos


Título: Re: mostrar ip local
Publicado por: ivantj en 9 Abril 2006, 16:27 pm
Para mostrar tu ip local pon:
1 label, 1 command button, 1 winsock

en las propiedades del command button pon:

Private Sub Command1_Click()
Label1.Caption = Winsock1.LocalIP
End Sub


Espero que te sirva


Título: Re: mostrar ip local
Publicado por: NYlOn en 9 Abril 2006, 21:55 pm
Esto es lo mismo que puso scode (sacado del API-Guide) pero le saque un par de cosas
En un modulo:
Código:
Public Const MIN_SOCKETS_REQD As Long = 1
Public Const WS_VERSION_REQD As Long = &H101
Public Const WS_VERSION_MAJOR As Long = WS_VERSION_REQD \ &H100 And &HFF&
Public Const WS_VERSION_MINOR As Long = WS_VERSION_REQD And &HFF&
Public Const SOCKET_ERROR As Long = -1
Public Const WSADESCRIPTION_LEN = 257
Public Const WSASYS_STATUS_LEN = 129
Public Const MAX_WSADescription = 256
Public Const MAX_WSASYSStatus = 128
Public Type WSAData
    wVersion As Integer
    wHighVersion As Integer
    szDescription(0 To MAX_WSADescription) As Byte
    szSystemStatus(0 To MAX_WSASYSStatus) As Byte
    wMaxSockets As Integer
    wMaxUDPDG As Integer
    dwVendorInfo As Long
End Type
Type WSADataInfo
    wVersion As Integer
    wHighVersion As Integer
    szDescription As String * WSADESCRIPTION_LEN
    szSystemStatus As String * WSASYS_STATUS_LEN
    iMaxSockets As Integer
    iMaxUdpDg As Integer
    lpVendorInfo As String
End Type
Public Type HOSTENT
    hName As Long
    hAliases As Long
    hAddrType As Integer
    hLen As Integer
    hAddrList As Long
End Type
Declare Function WSAStartup Lib "WSOCK32" (ByVal wVersionRequired As Long, lpWSADATA As WSAData) As Long
Declare Function gethostbyname Lib "WSOCK32" (ByVal szHost As String) As Long
Declare Sub CopyMemoryIP Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Public Function GetIPAddress() As String
    Dim sHostName As String * 256
    Dim lpHost As Long
    Dim HOST As HOSTENT
    Dim dwIPAddr As Long
    Dim tmpIPAddr() As Byte
    Dim I As Integer
    Dim sIPAddr As String
    If Not SocketsInitialize() Then
        GetIPAddress = ""
        Exit Function
    End If
    sHostName = Trim$(sHostName)
    lpHost = gethostbyname(sHostName)
    If lpHost = 0 Then
        GetIPAddress = ""
        MsgBox "Windows Sockets are not responding. " & "Unable to successfully get Host Name."
        Exit Function
    End If
    CopyMemoryIP HOST, lpHost, Len(HOST)
    CopyMemoryIP dwIPAddr, HOST.hAddrList, 4
    ReDim tmpIPAddr(1 To HOST.hLen)
    CopyMemoryIP tmpIPAddr(1), dwIPAddr, HOST.hLen
    For I = 1 To HOST.hLen
        sIPAddr = sIPAddr & tmpIPAddr(I) & "."
    Next
    GetIPAddress = Mid$(sIPAddr, 1, Len(sIPAddr) - 1)
End Function
Public Function HiByte(ByVal wParam As Integer)
    HiByte = wParam \ &H100 And &HFF&
End Function
Public Function LoByte(ByVal wParam As Integer)
    LoByte = wParam And &HFF&
End Function

Public Function SocketsInitialize() As Boolean
    Dim WSAD As WSAData
    Dim sLoByte As String
    Dim sHiByte As String
    If WSAStartup(WS_VERSION_REQD, WSAD) <> ERROR_SUCCESS Then
        MsgBox "The 32-bit Windows Socket is not responding."
        SocketsInitialize = False
        Exit Function
    End If
    If WSAD.wMaxSockets < MIN_SOCKETS_REQD Then
        MsgBox "This application requires a minimum of " & CStr(MIN_SOCKETS_REQD) & " supported sockets."
        SocketsInitialize = False
        Exit Function
    End If
    If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or (LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
        sHiByte = CStr(HiByte(WSAD.wVersion))
        sLoByte = CStr(LoByte(WSAD.wVersion))
        MsgBox "Sockets version " & sLoByte & "." & sHiByte & " is not supported by 32-bit Windows Sockets."
        SocketsInitialize = False
        Exit Function
    End If
    SocketsInitialize = True
End Function

Despues solo queda:
Código:
MsgBox GetIPAdress

Saludos.-