none
Ping network devices range of IP's RRS feed

  • Question

  • I am not a scripter; just a dumb network guy. I have been looking for days for a script to ping a range of IP's and return (preferably in Excel) what IP's are in use and not in use. It would be great if it would give hostname but I don't think that is possible with switches and routers. I am on a DoD network so I can't download and use the free tools out there. That limits my options. I need a simple IP range scan script to play with. I am hoping that will give me a start into your world to learn scripting and Powershell. In turn, I will be able to teach my guys and get them started. 
    Saturday, November 12, 2016 7:45 PM

Answers

  • Hello,

    I build a small script that do most of your post, except export to CSV.

    Here's the script:

    #---------------- Begining of Script -------------------

    # ENTER Base IP (First 3 position of IP Address)
    $BaseIP = "192.168.1"

    # ENTER Start IP (Min 1)
    $StartIP = 100

    # ENTER End IP (Max 254)
    $EndIP   = 150

    # Main logic
    while ($StartIP -le $EndIP)
       {
       $HostName  = ""
       $IPAddress = "$BaseIP.$StartIP"
       $TestIP    = Test-Connection $IPAddress -Quiet -Count 1

       if($TestIP)
            {  
             try {
                $HostName = ([System.Net.Dns]::GetHostEntry([IPAddress]$IPaddress)).hostname
                }
                catch { $HostName = "" }
             New-Object -TypeName PSCustomObject -Property @{
                 'Computer Name'   = $HostName
                 'IP Address'      = $IPAddress
                 'Response'        = 'Ok'
                 }
            }
        else
           {
             New-Object -TypeName PSCustomObject -Property @{
                 'IP Address' = $IPAddress
                 'Response'   = 'Time-out'
                 }
            } 
        $StartIP++
        }

    #---------------- End of Script -------------------

    Regards,


    Gilles Tremblay
    MCSE Server | Desktop | Messaging | Collaboration | Productivity | Mobility | Cloud Platform and Infrastructure

    Dont forget to mark as Answered if you found this post helpful.

    DISCLAIMER: This post is provided "AS IS" with no warranties of any kind, either expressed or implied, and confers no rights. Always test before!

    Sunday, November 13, 2016 2:38 AM

All replies

  • There are almost 500 scripts  here that can ping in a network.

    \_(ツ)_/

    Saturday, November 12, 2016 8:17 PM
  • Hello,

    I build a small script that do most of your post, except export to CSV.

    Here's the script:

    #---------------- Begining of Script -------------------

    # ENTER Base IP (First 3 position of IP Address)
    $BaseIP = "192.168.1"

    # ENTER Start IP (Min 1)
    $StartIP = 100

    # ENTER End IP (Max 254)
    $EndIP   = 150

    # Main logic
    while ($StartIP -le $EndIP)
       {
       $HostName  = ""
       $IPAddress = "$BaseIP.$StartIP"
       $TestIP    = Test-Connection $IPAddress -Quiet -Count 1

       if($TestIP)
            {  
             try {
                $HostName = ([System.Net.Dns]::GetHostEntry([IPAddress]$IPaddress)).hostname
                }
                catch { $HostName = "" }
             New-Object -TypeName PSCustomObject -Property @{
                 'Computer Name'   = $HostName
                 'IP Address'      = $IPAddress
                 'Response'        = 'Ok'
                 }
            }
        else
           {
             New-Object -TypeName PSCustomObject -Property @{
                 'IP Address' = $IPAddress
                 'Response'   = 'Time-out'
                 }
            } 
        $StartIP++
        }

    #---------------- End of Script -------------------

    Regards,


    Gilles Tremblay
    MCSE Server | Desktop | Messaging | Collaboration | Productivity | Mobility | Cloud Platform and Infrastructure

    Dont forget to mark as Answered if you found this post helpful.

    DISCLAIMER: This post is provided "AS IS" with no warranties of any kind, either expressed or implied, and confers no rights. Always test before!

    Sunday, November 13, 2016 2:38 AM