Results 1 to 19 of 19

Thread: Find Device on LAN

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    65

    Find Device on LAN

    I am on a roll, one thread every night! (this isn't my goal) Anyway, I was wondering if it is possible to look on the Local Area Network you are connected to, and create a list of attached devices. Kinda like logging into your router to view the attached devices, only doing it in VB. Is this possible? All i need to get is the name it Identifies itself as and it's IP address. (not a malware app of any kind) Thanks!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Find Device on LAN

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    65

    Re: Find Device on LAN

    Honestly, to a noob that looks like Spanish, but I will try it and see what I can get. I hope that will work. What should I do to use the code? just add it to a form and have 2 combo boxes? Thanks!

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Find Device on LAN

    The notes are in the comments. Just add the first part of the code to a module and then where the comments state "Behind a form" you place that code behind a form. it will duplicate a network neighborhood listing all computers on your LAN.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    65

    Re: Find Device on LAN

    Quote Originally Posted by RobDog888
    The notes are in the comments. Just add the first part of the code to a module and then where the comments state "Behind a form" you place that code behind a form. it will duplicate a network neighborhood listing all computers on your LAN.
    That is great! Will it reveal their IP addresses too?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Find Device on LAN

    No, but you can just write another function to ping the retrieved computer domain/name to get its IP addy.
    Then rinse and repeat for each found computer
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    65

    Re: Find Device on LAN

    Quote Originally Posted by RobDog888
    No, but you can just write another function to ping the retrieved computer domain/name to get its IP addy.
    Then rinse and repeat for each found computer
    Sounds good, but I might have to ask for help with that later on... because I know the terminology of what you said... just not how to code it Thanks for your help!

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Find Device on LAN

    Its not too hard you just need to use some winsock APIs to do it. If you search GetHostByName and IcmpSendEcho you should find examples or I can write one up if you want.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    65

    Re: Find Device on LAN

    If it isn't too much to bother you with, I would really appreciate that. I learn alot from the Sample code you guys give me, but I'm new to developing on the Windows Platform entirely (I'm probably the only Mac Boy in here ) Thank you so much. I know about 2,000 people that are going to appreciate this and not even know it!

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Find Device on LAN

    I made an example Its a quick and dirty one as there isnt enough/complete error checking but should get your started.

    Code:
    Option Explicit
    'Add 2 labels, 2 textboxes and 1 command button.
    
    Private Const MIN_SOCKETS_REQD = 1
    Private Const WSADescription_Len = 256
    Private Const WSASYS_Status_Len = 128
    
    Const SOCKET_ERROR = 0
    
    Private Type WSAdata
        wVersion As Integer
        wHighVersion As Integer
        szDescription(0 To 255) As Byte
        szSystemStatus(0 To 128) As Byte
        iMaxSockets As Integer
        iMaxUdpDg As Integer
        lpVendorInfo As Long
    End Type
    
    Private Type Hostent
        h_name As Long
        h_aliases As Long
        h_addrtype As Integer
        h_length As Integer
        h_addr_list As Long
    End Type
    
    Private Type IP_OPTION_INFORMATION
        TTL As Byte
        Tos As Byte
        flags As Byte
        OptionsSize As Long
        OptionsData As String * 128
    End Type
    
    Private Type IP_ECHO_REPLY
        Address(0 To 3) As Byte
        Status As Long
        RoundTripTime As Long
        DataSize As Integer
        Reserved As Integer
        data As Long
        Options As IP_OPTION_INFORMATION
    End Type
    
    Private Declare Function GetHostByName Lib "wsock32.dll" Alias "gethostbyname" (ByVal HostName As String) As Long
    
    Private Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVersionRequired&, lpWSAdata As WSAdata) As Long
    
    Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
    
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
    
    Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
    
    Private Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal HANDLE As Long) As Boolean
    
    Private Declare Function IcmpSendEcho Lib "ICMP" (ByVal IcmpHandle As Long, ByVal DestAddress As Long, _
    ByVal RequestData As String, ByVal RequestSize As Integer, RequestOptns As IP_OPTION_INFORMATION, ReplyBuffer As IP_ECHO_REPLY, _
    ByVal ReplySize As Long, ByVal TimeOut As Long) As Boolean
    
    Private Sub Command1_Click()
        CheckComputerStatus Text1.Text
    End Sub
    
    Private Sub Form_Load()
        Me.Width = 5000
        Me.Height = 2000
        Text1.Text = vbNullString
        Text2.Text = vbNullString
        Label1.Move 60, 120, 2000, 255
        Label2.Move 60 + Label1.Width + 60, 120, 2500, 255
        Text1.Move 60, Label1.Top + Label1.Height + 60, 2000, 315
        Text2.Move 60 + Label1.Width + 60, Label2.Top + Label2.Height + 60, 2500, 315
        Command1.Caption = "Ping Me"
        Command1.Height = 315
        Command1.Width = 1155
        Command1.Move Me.ScaleWidth - Command1.Width - 60, Me.ScaleHeight - 60 - Command1.Height
    End Sub
    
    Private Function CheckComputerStatus(ByVal HostName As String) As Boolean
    
        On Error GoTo My_Error
        
        Dim hostent_addr As Long
        Dim host As Hostent
        Dim hostip_addr As Long
        Dim temp_ip_address() As Byte
        Dim i As Integer
        Dim ip_address As String
        
        Dim hFile As Long, lpWSAdata As WSAdata
        Dim hHostent As Hostent, AddrList As Long
        Dim Address As Long, rIP As String
        Dim OptInfo As IP_OPTION_INFORMATION
        Dim EchoReply As IP_ECHO_REPLY
        Dim bRetVal As Boolean
        
        Me.Text2.Text = "Status: Checking..."
        DoEvents
        'GET HOST NAME
        Call WSAStartup(&H101, lpWSAdata)
        If GetHostByName(HostName + String(64 - Len(HostName), 0)) <> SOCKET_ERROR Then
            CopyMemory hHostent.h_name, ByVal GetHostByName(HostName + String(64 - Len(HostName), 0)), Len(hHostent)
            CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
            CopyMemory Address, ByVal AddrList, 4
            hFile = IcmpCreateFile()
            If hFile <> 0 Then
                'PING COMPUTER
                OptInfo.TTL = 255
                bRetVal = IcmpSendEcho(hFile, Address, String(32, "A"), 32, OptInfo, EchoReply, Len(EchoReply) + 8, 2000)
                If (bRetVal) Then
                    rIP = CStr(EchoReply.Address(0)) + "." + CStr(EchoReply.Address(1)) + "." + CStr(EchoReply.Address(2)) + "." + CStr(EchoReply.Address(3))
                End If
                If EchoReply.Status = 0 Then
                    Me.Text2.Text = HostName + " (" + rIP + ") " + Trim$(CStr(EchoReply.RoundTripTime)) + "ms"
                End If
            End If
            CheckComputerStatus = True
        End If
        Call IcmpCloseHandle(hFile)
        Call WSACleanup
        Exit Function
    My_Error:
        Me.Text2.Text = "Ping timeout"
    End Function
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    65

    Re: Find Device on LAN

    Thanks, I'll give it a whirl today. You guys are awesome!

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Find Device on LAN

    There probably are other ways that would be faster like if you are in a Active Directory network then you could query the AD database etc but without knowing more of your networks config I would have to go with this.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    65

    Re: Find Device on LAN

    Quote Originally Posted by RobDog888
    There probably are other ways that would be faster like if you are in a Active Directory network then you could query the AD database etc but without knowing more of your networks config I would have to go with this.
    Well, it will have to be compatible with most every home networks... I think it will work. I'm about to test as soon as I finish this one project in about 2hrs. Thanks Again!

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Find Device on LAN

    Yea winsock32.dll and icmp.dll together require Windows Sockets 2.0 so it should work on almost any system.

    no prob.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    65

    Re: Find Device on LAN

    I finally finished debugging my other app and I got to test this code out... it works for all of the computers in my network, but unfortunately it doesn't seem to identify anything BUT computers... I actually really need it to target iPhones and iPod touch's I'm not sure what the difference in coding would be, or perhaps I'm doing it wrong, but I like what you gave me, it's pretty nifty and I think if I have a little guidance on how to modify it, it will work wonderfully. Thanks for all your hard work!

  16. #16
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Find Device on LAN

    iPhones & iPods plug into LAN? I thought they'd be USB devices?

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    65

    Re: Find Device on LAN

    they are USB devices, but they have WiFi capability. When they are jailbroken, they can do much more. I just need to make a small utility to help find say.. an iPhone on your network and get it's IP. This would be to avoid logging into your router... which is a long process

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Find Device on LAN

    Ah then that may be a different process. Im not familiar with mobile programming.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    65

    Re: Find Device on LAN

    Well, I would think that it would be close... Can we just populate a list of all devices attached to the network? it may not be that simple, but they are just like any other device that requests an IP address etc... it supports WEP encryption and several others. I wouldn't think it's that hard, but it might be in VB idk.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width