Network IP and Hostname

I need to scan thru a LAN and list all active computers. Get their hostname and username. I have made a subnet-scanner, which scans forexample 192.168.2. and a range from 0 to 255.
This doesn't go very quickly, so I wondered if there was some other way to do this.

If 200p is not enough, I can give you more. Also, my internet connection is VERY restricted, so it might be a while before I check for an response.

Thanks,

Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
LVL 2
mannenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
You can ping all of the hosts in your domain... Add the following code to a module in your program then you can call IsHostAlive()

It works this way:

   If IsHostAlive("207.19.204.11") = True Then
      'Host is alive... Do whatever
   Else
      'Host is dead...
   End If


There are a couple other routines included here as well...

   GetHostInfo() gets host information
   GetPingString() pings a host and returns a standard ping line.


Cheers!




THE CODE:


Option Explicit
Private Const WS32_NOT_ENOUGH_SOCKETS = -4
Private Const WS32_NOT_SUPPORTED = -3
Private Const WS32_NOT_RESPONDING = -2
Private Const IP_STATUS_BASE = 11000
Private Const IP_SUCCESS = 0
Private Const IP_BUF_TOO_SMALL = (11000 + 1)
Private Const IP_DEST_NET_UNREACHABLE = (11000 + 2)
Private Const IP_DEST_HOST_UNREACHABLE = (11000 + 3)
Private Const IP_DEST_PROT_UNREACHABLE = (11000 + 4)
Private Const IP_DEST_PORT_UNREACHABLE = (11000 + 5)
Private Const IP_NO_RESOURCES = (11000 + 6)
Private Const IP_BAD_OPTION = (11000 + 7)
Private Const IP_HW_ERROR = (11000 + 8)
Private Const IP_PACKET_TOO_BIG = (11000 + 9)
Private Const IP_REQ_TIMED_OUT = (11000 + 10)
Private Const IP_BAD_REQ = (11000 + 11)
Private Const IP_BAD_ROUTE = (11000 + 12)
Private Const IP_TTL_EXPIRED_TRANSIT = (11000 + 13)
Private Const IP_TTL_EXPIRED_REASSEM = (11000 + 14)
Private Const IP_PARAM_PROBLEM = (11000 + 15)
Private Const IP_SOURCE_QUENCH = (11000 + 16)
Private Const IP_OPTION_TOO_BIG = (11000 + 17)
Private Const IP_BAD_DESTINATION = (11000 + 18)
Private Const IP_ADDR_DELETED = (11000 + 19)
Private Const IP_SPEC_MTU_CHANGE = (11000 + 20)
Private Const IP_MTU_CHANGE = (11000 + 21)
Private Const IP_UNLOAD = (11000 + 22)
Private Const IP_ADDR_ADDED = (11000 + 23)
Private Const IP_GENERAL_FAILURE = (11000 + 50)
Private Const MAX_IP_STATUS = 11000 + 50
Private Const IP_PENDING = (11000 + 255)
Private Const PING_TIMEOUT = 200
Private Const WS_VERSION_REQD = &H101
Private Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
Private Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
Private Const MIN_SOCKETS_REQD = 1
Private Const SOCKET_ERROR = -1
Private Const WSADescription_Len = 256
Private Const WSASYS_Status_Len = 128
Private Type ICMP_OPTIONS
    Ttl             As Byte
    Tos             As Byte
    Flags           As Byte
    OptionsSize     As Byte
    OptionsData     As Long
End Type
Private Type ICMP_ECHO_REPLY
    Address         As Long
    status          As Long
    RoundTripTime   As Long
    DataSize        As Integer
    Reserved        As Integer
    DataPointer     As Long
    Options         As ICMP_OPTIONS
    Data            As String * 250
End Type
Private Type HOSTENT
    hName As Long
    hAliases As Long
    hAddrType As Integer
    hLength As Integer
    hAddrList As Long
End Type
Public Type LHOSTENTRY
    hName As String
    hAddress As String
    hStatus As String
End Type
Private Type WSADATA
    wversion As Integer
    wHighVersion As Integer
    szDescription(0 To WSADescription_Len) As Byte
    szSystemStatus(0 To WSASYS_Status_Len) As Byte
    iMaxSockets As Integer
    iMaxUdpDg As Integer
    lpszVendorInfo As Long
End Type
Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
Private Declare Function IcmpCloseHandle Lib "icmp.dll" _
    (ByVal IcmpHandle As Long) As Long
Private Declare Function IcmpSendEcho Lib "icmp.dll" _
    (ByVal IcmpHandle As Long, ByVal DestinationAddress As Long, _
    ByVal RequestData As String, ByVal RequestSize As Integer, _
    ByVal RequestOptions As Long, ReplyBuffer As ICMP_ECHO_REPLY, _
    ByVal ReplySize As Long, ByVal Timeout As Long) As Long
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" _
   (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 RtlMoveMemory Lib "kernel32" (hpvDest As Any, _
    ByVal hpvSource As Long, ByVal cbCopy As Long)
Private G_lhEntry As LHOSTENTRY

Public Function GetHostInfo(lHost As String) As LHOSTENTRY
    Dim WSAD As WSADATA
    Dim rVal As Long
    Dim hostname As String * 256
    Dim hostent_addr As Long
    Dim host As HOSTENT
    Dim hostip_addr As Long
    Dim temp_ip_address() As Byte
    Dim iVal As Integer
    Dim ip_address As String
   
    rVal = WSAStartup(WS_VERSION_REQD, WSAD)
    If rVal <> 0 Then
        GetHostInfo.hStatus = WS32_NOT_RESPONDING
        Exit Function
    End If
    If CvtLoByte(WSAD.wversion) < WS_VERSION_MAJOR Or _
       (CvtLoByte(WSAD.wversion) = WS_VERSION_MAJOR And _
        CvtHiByte(WSAD.wversion) < WS_VERSION_MINOR) Then
        GetHostInfo.hStatus = WS32_NOT_SUPPORTED
        WSACleanup
        Exit Function
    End If
    If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
        GetHostInfo.hStatus = WS32_NOT_ENOUGH_SOCKETS
        WSACleanup
        Exit Function
    End If
   
    GetHostInfo.hStatus = SOCKET_ERROR
    GetHostInfo.hName = Trim$(LCase$(lHost))
    hostname = Left$(lHost + String(256, Chr$(0)), 256)
    hostent_addr = gethostbyname(hostname)
    If hostent_addr = 0 Then
        WSACleanup
        Exit Function
    End If
    RtlMoveMemory host, hostent_addr, LenB(host)
    RtlMoveMemory hostip_addr, host.hAddrList, 4
    ReDim temp_ip_address(1 To host.hLength)
    RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength
    For iVal = 1 To host.hLength
        ip_address = ip_address & temp_ip_address(iVal) & "."
    Next
    ip_address = Mid$(ip_address, 1, Len(ip_address) - 1)
    GetHostInfo.hAddress = ip_address
    GetHostInfo.hStatus = IP_SUCCESS
    WSACleanup
End Function

Public Function GetPingMsg(status As Long) As String
    Dim msg As String
    Select Case status
        Case WS32_NOT_ENOUGH_SOCKETS:  msg = "Not enough sockets available"
        Case WS32_NOT_SUPPORTED:       msg = "Socket version not supported"
        Case WS32_NOT_RESPONDING:      msg = "Winsock 32 not responding"
        Case IP_SUCCESS:               msg = "OK"
        Case IP_BUF_TOO_SMALL:         msg = "IP buf too small"
        Case IP_DEST_NET_UNREACHABLE:  msg = "Destination network unreachable"
        Case IP_DEST_HOST_UNREACHABLE: msg = "Destination host unreachable"
        Case IP_DEST_PROT_UNREACHABLE: msg = "Destination protocol unreachable"
        Case IP_DEST_PORT_UNREACHABLE: msg = "Destination port unreachable"
        Case IP_NO_RESOURCES:          msg = "IP no resources"
        Case IP_BAD_OPTION:            msg = "IP bad option"
        Case IP_HW_ERROR:              msg = "IP hardware error"
        Case IP_PACKET_TOO_BIG:        msg = "IP packet too big"
        Case IP_REQ_TIMED_OUT:         msg = "Request timed out"
        Case IP_BAD_REQ:               msg = "Bad request"
        Case IP_BAD_ROUTE:             msg = "Bad route"
        Case IP_TTL_EXPIRED_TRANSIT:   msg = "IP TTL expired transit"
        Case IP_TTL_EXPIRED_REASSEM:   msg = "IP TTL expired reassem"
        Case IP_PARAM_PROBLEM:         msg = "IP param problem"
        Case IP_SOURCE_QUENCH:         msg = "IP source quench"
        Case IP_OPTION_TOO_BIG:        msg = "IP option too big"
        Case IP_BAD_DESTINATION:       msg = "IP bad destination"
        Case IP_ADDR_DELETED:          msg = "IP address deleted"
        Case IP_SPEC_MTU_CHANGE:       msg = "IP spec mtu change"
        Case IP_MTU_CHANGE:            msg = "IP mtu change"
        Case IP_UNLOAD:                msg = "IP unload"
        Case IP_ADDR_ADDED:            msg = "IP address added"
        Case IP_GENERAL_FAILURE:       msg = "IP general failure"
        Case IP_PENDING:               msg = "IP pending"
        Case PING_TIMEOUT:             msg = "Ping timeout"
        Case Else:                     msg = "Unknown message returned"
    End Select
    GetPingMsg = msg
End Function


Private Function CvtHiByte(ByVal wParam As Integer)
    CvtHiByte = wParam \ &H100 And &HFF&
End Function


Private Function CvtLoByte(ByVal wParam As Integer)
    CvtLoByte = wParam And &HFF&
End Function


Public Function IsHostAlive(lHost As String) As Boolean
    Dim ECHO As ICMP_ECHO_REPLY
    Dim pos As Integer
    IsHostAlive = False
    SysPing lHost, ECHO
    If ECHO.status = IP_SUCCESS Then IsHostAlive = True
End Function

Public Function GetPingString(lHost As String) As String
    Dim ECHO As ICMP_ECHO_REPLY
    Dim pos As Integer
    SysPing lHost, ECHO
    If ECHO.status = IP_SUCCESS Then
        GetPingString = "Reply from " & G_lhEntry.hAddress & ": bytes=" & Trim$(CStr(ECHO.DataSize)) _
            & " time=" & Trim$(CStr(ECHO.RoundTripTime)) & "ms TTL=" _
            & Trim$(CStr(ECHO.Options.Ttl))
    Else
        GetPingString = GetPingMsg(ECHO.status)
    End If
End Function

Private Function SysPing(lhostname As String, ECHO As ICMP_ECHO_REPLY, Optional EchoString As String) As Long
    Dim WSAD As WSADATA
    Dim hPort As Long
    Dim dwAddr As Long
    Dim iOpt As Long
    Dim rVal As Long
    Dim eString As String
    Dim szLoByte As String
    Dim szHiByte As String
    Dim szBuf As String
    eString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345": If Not EchoString = "" Then eString = EchoString
    G_lhEntry = GetHostInfo(lhostname)
    If Not G_lhEntry.hStatus = 0 Then
        SysPing = IP_BAD_DESTINATION
        ECHO.status = IP_BAD_DESTINATION
        Exit Function
    End If
    dwAddr = CvtIPAddrClng(G_lhEntry.hAddress)
    If dwAddr = 0 Then
        SysPing = IP_BAD_DESTINATION
        ECHO.status = IP_BAD_DESTINATION
        Exit Function
    End If
    rVal = WSAStartup(WS_VERSION_REQD, WSAD)
    If rVal <> 0 Then
        SysPing = WS32_NOT_RESPONDING
        ECHO.status = WS32_NOT_RESPONDING
        Exit Function
    End If
    If CvtLoByte(WSAD.wversion) < WS_VERSION_MAJOR Or _
       (CvtLoByte(WSAD.wversion) = WS_VERSION_MAJOR And _
        CvtHiByte(WSAD.wversion) < WS_VERSION_MINOR) Then
        SysPing = WS32_NOT_SUPPORTED
        ECHO.status = WS32_NOT_SUPPORTED
        WSACleanup
        Exit Function
    End If
    If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
        SysPing = WS32_NOT_ENOUGH_SOCKETS
        ECHO.status = WS32_NOT_ENOUGH_SOCKETS
        WSACleanup
        Exit Function
    End If
    hPort = IcmpCreateFile()
    rVal = IcmpSendEcho(hPort, dwAddr, eString, Len(eString), 0, ECHO, Len(ECHO), PING_TIMEOUT)
    If rVal = 1 Then
        SysPing = IP_SUCCESS
    Else
        If ECHO.status = 0 Then ECHO.status = IP_DEST_NET_UNREACHABLE
        SysPing = ECHO.status * -1
    End If
    IcmpCloseHandle hPort
    WSACleanup
End Function
Private Function CvtIPAddrClng(ByVal tmp As String) As Long
    Dim iVal As Integer
    Dim IpWord(4) As String
    CvtIPAddrClng = 0: iVal = 0
    While InStr(tmp, ".") > 0
        iVal = iVal + 1
        IpWord(iVal) = Mid(tmp, 1, InStr(tmp, ".") - 1)
        tmp = Mid(tmp, InStr(tmp, ".") + 1)
    Wend
    iVal = iVal + 1
    IpWord(iVal) = tmp
    If iVal <> 4 Then Exit Function
    CvtIPAddrClng = Val("&H" & Right("00" & Hex(IpWord(4)), 2) & _
        Right("00" & Hex(IpWord(3)), 2) & Right("00" & Hex(IpWord(2)), 2) & _
        Right("00" & Hex(IpWord(1)), 2))
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mannenAuthor Commented:
Well, this looks good. Trying the code tonight.

Thanks,

Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
0
mannenAuthor Commented:
Thanks, that was a complete answer to my question. BUT:

I really asked wrong, what I wanted to know was: How do I get a computers name on a network, using the computers IP.

I am giving you the points, since you answered this question though...

Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mcriderCommented:
Ok, here you go... Add the following to a MODULE then you can call this anywhere in your program to convert an IP address to a hostname:

   Dim lHostName As String
   lHostName = LookupIP("127.0.0.1")

The variable lHostName will contain the hostname of whatever IP address you pass...

Since this is a completely different answer, I would appreciate it if you open a new question with the title "FOR MCRIDER ONLY" and assign some points to it so I can get credit for this.


Cheers!



THE CODE:

    Option Explicit
    Private Type ICMPReqOpt
        TTL As Byte ' time-to-live
        tos As Byte ' type-of-service
        flags As Byte ' see below
        optsize As Byte ' length of options string
        options As String ' use empty string
    End Type
    Private Type ICMPEchoReply
        Address(1 To 4) As Byte ' address of system responding
        status As Long ' error code
        triptime As Long ' time in milliseconds
        datasize As Integer ' buffer size
        reserved As Integer ' not used
        replydata As String ' buffer returned
        ipoptions As ICMPReqOpt ' options structure
    End Type
    ' ICMP API calls
    Private Declare Function IcmpCreateFile Lib "ICMP.DLL" () As Long
    Private Declare Function IcmpCloseHandle Lib "ICMP.DLL" _
        (ByVal lngHandle As Long) As Integer
    Private Declare Function IcmpSendEcho Lib "ICMP.DLL" _
        (ByVal lngHandle As Long, ByVal lIP As Long, _
        strData As String, ByVal intDataLen As Integer, _
        usrOpt As ICMPReqOpt, bytBuff As Byte, _
        ByVal lngRepLen As Long, ByVal lTimeOut As Long) As Long
    Private Declare Function IcmpGetLastError Lib "wsock32.dll" _
        Alias "WSAGetLastError" () As Long
    ' ICMP error codes
    Private Const ICMP_SUCCESS = 0
    Private Const ICMP_BUFFER_TOO_SMALL = 11001
    Private Const ICMP_NET_UNREACHABLE = 11002
    Private Const ICMP_HOST_UNREACHABLE = 11003
    Private Const ICMP_DEST_PROT_UNREACHABLE = 11004
    Private Const ICMP_DEST_PORT_UNREACHABLE = 11005
    Private Const ICMP_NO_RESOURCES = 11006
    Private Const ICMP_BAD_OPTION = 11007
    Private Const ICMP_HW_ERROR = 11008
    Private Const ICMP_PACKET_TOO_BIG = 11009
    Private Const ICMP_REQ_TIMED_OUT = 11010
    Private Const ICMP_BAD_REQ = 11011
    Private Const ICMP_BAD_ROUTE = 11012
    Private Const ICMP_TTL_EXPIRED_TRANSMIT = 11013
    Private Const ICMP_TTL_EXPIRED_REASSEM = 11014
    Private Const ICMP_PARAM_PROBLEM = 11015
    Private Const ICMP_SOURCE_QUENCH = 11016
    Private Const ICMP_OPTION_TOO_BIG = 11017
    Private Const ICMP_BAD_DESTINATION = 11018
    Private Const ICMP_ADDRESS_DELETED = 11019
    Private Const ICMP_SPEC_MTU_CHANGE = 11020
    Private Const ICMP_MTU_CHANGE = 11021
    Private Const ICMP_UNLOAD = 11022
    Private Const ICMP_GENERAL_FAILURE = 11050
    Private Const ICMP_PENDING = 11255
    ' ICMP flags
    Private Const ICMP_FLAG_NO_FRAGMENT = 2
    ' ICMP type-of-service options
    Private Const ICMP_ECHO_REQUEST = 7
    Private Const ICMP_END_OF_LIST = 0
    Private Const ICMP_SECURITY = 1
    Private Const ICMP_LOOSE_SOURCE_ROUTE = &H82
    Private Const ICMP_STRICT_SOURCE_ROUTE = &H83
    Private Const ICMP_RECORD_ROUTE = &H89
    Private Const ICMP_TIMESTAMP = 7
    Private Const ICMP_STREAM_id = &H44
    Private Const ICMP_NOOP = &H88
    ' we also need some basic Winsock stuff
    Private Const WSADescription_Len = 256
    Private Const WSASYS_Status_Len = 128
    Private Const AF_INET = 2
   
    Private Type WSADATA
        wversion As Integer
        whighversion As Integer
        szDescription(0 To WSADescription_Len) As Byte
        szSystemStatus(0 To WSASYS_Status_Len) As Byte
        imaxsockets As Integer
        imaxudp As Integer
        lpszvenderinfo As Long
    End Type
    Private Declare Function gethostname Lib "wsock32.dll" _
        (ByVal hostname As String, ByVal nbytes As Long) As Long
    Private Declare Function gethostbyname Lib "wsock32.dll" _
        (ByVal hostname As String) As Long
    Private Declare Function gethostbyaddr Lib "wsock32.dll" _
        (haddr As Long, ByVal hnlen As Long, ByVal addrtype As Long) As Long
    Private Declare Function WSAStartup Lib "wsock32.dll" _
        (ByVal VersionReq As Long, WSADataReturn As WSADATA) As Long
    Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
    ' and a way to copy memory directly...
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (xDest As Any, xSource As Any, ByVal nbytes As Long)
    Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" _
      (lpString As Any) As Long
    ' finally, we need a handle for ICMP
    Private hICMP As Long
    Function StartWSA() As Boolean
        Dim udtWSAData As WSADATA
        StartWSA = True
        If WSAStartup(257, udtWSAData) <> 0 Then
            MsgBox "Unable to initialize Winsock", vbOKOnly, "Winsock Error"
            StartWSA = False
            Exit Function
        End If
        hICMP = IcmpCreateFile()
        If hICMP = 0 Then
            MsgBox "Unable to initialize ICMP", vbOKOnly, "ICMP Error"
            StartWSA = False
        End If
    End Function
    Private Function TextToIP(ByVal IPAddress As String) As Long
    Dim x As Integer ' scratch
    Dim iOctet As Integer ' octet value
    Dim bytIP(1 To 4) As Byte ' temp IP storage
    Dim lIP As Long ' IP value
    Dim iDots As Integer ' count of dots found
    lIP = 0
    iOctet = 0
    iDots = 0
    For x = 1 To Len(IPAddress)
      If Mid$(IPAddress, x, 1) = "." Then
        iDots = iDots + 1
        If iDots > 3 Then Exit For ' bad format!
        bytIP(iDots) = iOctet
        iOctet = 0
      Else
        ' add digit but restrict to 8 bits
        iOctet = (iOctet * 10 + Val("0" & Mid$(IPAddress, x, 1))) And 255
      End If
    Next 'x
    bytIP(4) = iOctet ' save last one
    CopyMemory lIP, bytIP(1), 4 ' copy to LONG value
    TextToIP = lIP ' copy to return value
    End Function
    Private Function IPToText(ByVal IPAddress As String) As String
        IPToText = CStr(Asc(IPAddress)) & "." & _
            CStr(Asc(Mid$(IPAddress, 2, 1))) & "." & _
            CStr(Asc(Mid$(IPAddress, 3, 1))) & "." & _
            CStr(Asc(Mid$(IPAddress, 4, 1)))
    End Function
    Private Function MyHostName() As String
        Dim sTemp As String
        Dim x As Long
        sTemp = Space$(256)
        x = gethostname(sTemp, Len(sTemp))
        x = InStr(sTemp, vbNullChar)
        If x > 0 Then sTemp = Left$(sTemp, x - 1)
        MyHostName = sTemp
    End Function
    Function LookupIP(ByVal IP_Address As String) As String
        ' routine to convert IP to hostname
        Dim x As Long ' scratch
        Dim nbytes As Long
        Dim sTarget As String ' null-delimited hostname
        Dim lHostent As Long ' address of hostent structure
        Dim lHEName As Long ' address of name pointer
        Dim lHEAlias As Long ' address of alias pointer
        Dim lHEAddress As Long ' address of address pointer
        Dim lIPPointer As Long ' address of IP address
        Dim lAPointer As Long ' address of Alias
       
        Dim iAliasCount As Long
        Dim iAddressCount As Long
        Dim sIP() As String
        Dim sAlias() As String
        Dim sAddress() As String
       
        'STARTUP SOCKET
        If StartWSA() = False Then
            LookupIP = ""
            Exit Function ' failed!
        End If
        'default values
        iAliasCount = 0
        iAddressCount = 0
        LookupIP = ""
        ' lookup by IP or name
        If IsNumeric(Left$(IP_Address, 1)) Then
            lHostent = gethostbyaddr(TextToIP(IP_Address), 4, AF_INET)
        Else
            sTarget = IP_Address & vbNullChar
            lHostent = gethostbyname(sTarget) ' do actual winsock call
        End If
        If lHostent = 0 Then
            LookupIP = ""
            Exit Function ' failed!
        End If
        lHEName = lHostent ' set pointer addresses
        lHEAlias = lHostent + 4
        lHEAddress = lHostent + 12
        ' convert addresses of pointers to the pointers...
        CopyMemory lHEName, ByVal lHEName, 4
        CopyMemory lHEAlias, ByVal lHEAlias, 4
        CopyMemory lHEAddress, ByVal lHEAddress, 4
       
        ' Get resolved hostname
        nbytes = lstrlen(ByVal lHEName)
        If nbytes > 0 Then
        IP_Address = Space$(nbytes)
        CopyMemory ByVal IP_Address, ByVal lHEName, nbytes
        LookupIP = IP_Address
        End If
       
        'CLEAN UP SOCKET
        If hICMP Then Call IcmpCloseHandle(hICMP)
        Call WSACleanup
    End Function
   
   
0
mannenAuthor Commented:
Thanks!!

Ofcourse I will give you some more points...

I will post a new question with your suggested title 'For McRider only' in the next 24 hours.

Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
0
mcriderCommented:
Cool! Glad I could help you again!


Cheers!
0
mannenAuthor Commented:
Oops... don't jump through the roof yet :(

Sorry, but the code didn't work, maybe I am doing something wrong, I don't know. First I tried to implement it to my program, that didn't work, then I did this:

1. Opened a new project.
2. Added your code to a module.
3. Added a form with two textboxes and one commandbutton.
4. Made the commandbutton code say:
    Text2.Text = LookupIP(Text1.Text)

This didn't work, do you have any idea?

Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
0
mcriderCommented:
Whoa! I just did some testing and found a HUGE bug in microsoft's winsock driver!

The gethostbyaddr API will only work properly if there is an entry in the \WINDOWS\HOSTS file for the IP address.  This is NOT supposed to happen with DNS enabled!

Ok... Using the code I gave you, try this:

Add an entry to the HOSTS file for one of your systems you're trying to identify and run your code.  If you don't have a HOSTS file in the WINDOWS directory, microsoft provides a sample file called HOSTS.SAM.  Just copy the HOSTS.SAM to HOSTS and then edit it to add a host...  The code will work after you do this...


Cheers!
0
mannenAuthor Commented:
I'm terribly sorry, McRider...

But I have had a VERY busy time at work the last weeks, and forgot all about my question. I am sorry, but this solution is not acceptable... You realize, ofcourse, that it is not your fault. If you want the points for this answer, I will give you them for your trouble.

If you want the points, just say so in a comment here.

Thanks for some excellent help and thanks for trying. You are a really good programmer :)

Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.