Results 1 to 16 of 16

Thread: List IP's on a network

  1. #1

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Question List IP's on a network

    How do get a list of all the pc's connected on my network and list them in a list box. its so i can send a message to the client app and tell it to shutdown, restart, log off etc.
    -BoKu-

  2. #2

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Re: List IP's on a network

    doesnt anybody know how to do this?
    -BoKu-

  3. #3
    Addicted Member Hammad's Avatar
    Join Date
    Mar 2003
    Location
    Pakistan
    Posts
    145

    Smile Re: List IP's on a network

    you can get all names of computer which are on network using winsock control and send them message too.
    Hammad Umar

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

    Re: List IP's on a network

    This will simulate network neighborhood using two combos.
    VB Code:
    1. 'IN A MODULE
    2. Option Explicit
    3.  
    4. Public Type SERVER_INFO_100
    5.     sv100_platform_id                    As Long
    6.     sv100_name                           As Long
    7. End Type
    8.  
    9. Public Const SV_TYPE_DOMAIN_ENUM         As Long = &H80000000
    10. Public Const SV_TYPE_ALL                 As Long = &HFFFFFFFF
    11. Public Const SV_TYPE_SQLSERVER           As Long = &H4
    12. Public Const MAX_PREFERRED_LENGTH        As Long = -1
    13. Public Const NERR_SUCCESS                As Long = 0&
    14. Public Const ERROR_REQ_NOT_ACCEP         As Long = 71&
    15. Public Const ERROR_MORE_DATA             As Long = 234&
    16. Public Const NERR_BASE                   As Long = 2100
    17. Public Const NERR_InvalidComputer = (NERR_BASE + 251)
    18.  
    19. Public Declare Function NetServerEnum Lib "netapi32" (ByVal servername As Long, ByVal level As Long, buf As Any, _
    20. ByVal prefmaxlen As Long, entriesread As Long, totalentries As Long, ByVal servertype As Long, ByVal domain As Long, _
    21. resume_handle As Long) As Long
    22.  
    23. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
    24.    
    25. Public Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long
    26.  
    27. Public Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
    28.  
    29. Public Function GetServers(sDomain As String, sType As Long) As String()
    30.  
    31.     Dim bufptr              As Long
    32.     Dim dwEntriesread       As Long
    33.     Dim dwTotalentries      As Long
    34.     Dim dwResumehandle      As Long
    35.     Dim se100               As SERVER_INFO_100
    36.     Dim success             As Long
    37.     Dim nStructSize         As Long
    38.     Dim Cnt                 As Long
    39.    
    40.     nStructSize = LenB(se100)
    41.     success = NetServerEnum(0&, 100, bufptr, MAX_PREFERRED_LENGTH, dwEntriesread, dwTotalentries, sType, StrPtr(sDomain), dwResumehandle)
    42.     'success = 71 'NO ACTIVE 'DOMAIN'
    43.     If success = NERR_SUCCESS And success <> ERROR_MORE_DATA Then
    44.         Dim compNames() As String
    45.         ReDim compNames(dwEntriesread)
    46.         For Cnt = 0 To dwEntriesread - 1
    47.             CopyMemory se100, ByVal bufptr + (nStructSize * Cnt), nStructSize
    48.             compNames(Cnt) = GetPointerToByteStringW(se100.sv100_name)
    49.             DoEvents
    50.         Next
    51.     End If
    52.     Call NetApiBufferFree(bufptr)
    53.     GetServers = compNames
    54.    
    55. End Function
    56.  
    57. Public Function GetPointerToByteStringW(ByVal dwData As Long) As String
    58.  
    59.     Dim tmp() As Byte
    60.     Dim tmplen As Long
    61.    
    62.     If dwData <> 0 Then
    63.         tmplen = lstrlenW(dwData) * 2
    64.         If tmplen <> 0 Then
    65.             ReDim tmp(0 To (tmplen - 1)) As Byte
    66.             CopyMemory tmp(0), ByVal dwData, tmplen
    67.             GetPointerToByteStringW = tmp
    68.         End If
    69.     End If
    70.    
    71. End Function
    Usage:
    VB Code:
    1. 'BEHIND A FORM WITH TWO COMBO'S (cboDomain and cboComputer)
    2. Private Sub Form_Load()
    3.  
    4.     Dim compNames() As String
    5.  
    6.     'SETUP THE DOMAIN COMBO BOX
    7.     compNames = GetServers(vbNullString, SV_TYPE_DOMAIN_ENUM)
    8.     For x = LBound(compNames) To UBound(compNames) - 1
    9.         cboDomain.AddItem compNames(x)
    10.     Next
    11.     cboDomain.ListIndex = 0
    12.  
    13. End Sub
    14.  
    15. Private Sub cboDomain_Click()
    16.     'NEED TO CLEAR CBOCOMPUTER AND RELOAD WITH COMPUTERS IN THE NEWLY SELECTED DOMAIN
    17.     'SETUP THE COMPUTER COMBO BOX
    18.     On Error GoTo No_Bugs
    19.    
    20.     Dim compNames() As String
    21.     Dim compName As String
    22.     Dim x As Integer
    23.    
    24.     cboComputer.Clear
    25.     x = 0
    26.     compNames = GetServers(cboDomain.Text, SV_TYPE_ALL)
    27.     If UBound(compNames) > 0 Then
    28.         For x = LBound(compNames) To UBound(compNames) - 1
    29.             cboComputer.AddItem compNames(x)
    30.         Next
    31.         cboComputer.ListIndex = 0
    32.     End If
    33.     Exit Sub
    34.    
    35. No_Bugs:
    36.     If Err.Number = "9" Then
    37.         cboDomain.RemoveItem (cboDomain.ListIndex)
    38.         cboDomain.ListIndex = 0
    39.         compNames = GetServers(cboDomain.Text, SV_TYPE_ALL)
    40.         Resume
    41.     Else
    42.         MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation, App.ProductName
    43.     End If
    44.    
    45. End Sub
    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
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Re: List IP's on a network

    Hey Rob. If I remove all computers from the network, i get an error and go into debug mode and is highlit like this....is this ok?

    ----------------------------------

    Private Sub Form_Load()

    Dim compNames() As String

    'SETUP THE DOMAIN COMBO BOX
    compNames = GetServers(vbNullString, SV_TYPE_DOMAIN_ENUM)
    For x = LBound(compNames) To UBound(compNames) - 1
    cboDomain.AddItem compNames(x)
    Next
    cboDomain.ListIndex = 0

    End Sub
    -BoKu-

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

    Re: List IP's on a network

    No, then your not detecting any domains/workgroups at all so the for statement is for x = 0 to 0 - 1 which gives an error. You can trap for when you get nothing with an If block surrounding the for loop.
    VB Code:
    1. If LBound(compNames)  = 0 And LBound(compNames) = 0 Then
    2.     MsgBox "No Domains/Workgroups Detected"
    3. Else
    4.     'Do all the for loop stuff in here
    5.  
    6. End If
    Did you unplug your cable
    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
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Re: List IP's on a network

    do u mean the coding like this:

    'BEHIND A FORM WITH TWO COMBO'S (cboDomain and cboComputer)
    Private Sub Form_Load()

    Dim compNames() As String

    'SETUP THE DOMAIN COMBO BOX
    compNames = GetServers(vbNullString, SV_TYPE_DOMAIN_ENUM)

    If LBound(compNames) = 0 And LBound(compNames) = 0 Then
    MsgBox "No Domains/Workgroups Detected"
    Else

    For x = LBound(compNames) To UBound(compNames) - 1
    cboDomain.AddItem compNames(x)
    Next
    cboDomain.ListIndex = 0

    End If

    End Sub
    -BoKu-

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: List IP's on a network

    I would Clear the listbox first, and post the code in the Form_Activate instead.
    You may want to call it again.

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

    Re: List IP's on a network

    Yes like that. No need to clear the combo box if this is on the Form_Load event unless you added items
    to it at design time.
    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

  10. #10

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Re: List IP's on a network

    hmmm now when i run it i get another error: "Subscript out of range"

    and this is highlit

    --------------------------------

    'BEHIND A FORM WITH TWO COMBO'S (cboDomain and cboComputer)
    Private Sub Form_Load()

    Dim compNames() As String

    'SETUP THE DOMAIN COMBO BOX
    compNames = GetServers(vbNullString, SV_TYPE_DOMAIN_ENUM)

    If LBound(compNames) = 0 And LBound(compNames) = 0 Then
    -BoKu-

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

    Re: List IP's on a network

    Did you add the other code to a module? Are you connected to a network? Try stepping through the code to see how far you get.
    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

  12. #12

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Re: List IP's on a network

    No i didnt add the code to a module, i added it to the right bit. LOL no im not at the moment, but that wont be fixed until friday. Thanks for the help tho, its been great!
    -BoKu-

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

    Re: List IP's on a network

    Ok, if you still have any issues post back tomorrow.
    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

  14. #14
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: List IP's on a network

    Quote Originally Posted by boku
    How do get a list of all the pc's connected on my network and list them in a list box. its so i can send a message to the client app and tell it to shutdown, restart, log off etc.
    Try to go to this Site. It may help you.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

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

    Re: List IP's on a network

    Quote Originally Posted by Simply Me
    Try to go to this Site. It may help you.
    He needs to be connected to a network or workgroup first
    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

  16. #16
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: List IP's on a network

    Hi there RobDog888, will you code work on all Windows OS? How about a network with different Workgroups? I've been searching for quite awhile now for something like your code does, though I havent tried it yet as of this moment.

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