Results 1 to 4 of 4

NSLookup host name to IP then ping results.

Threaded View

  1. #1
    Registered User
    Join Date
    07-18-2012
    Location
    cincinnati, ohio
    MS-Off Ver
    Excel 2007
    Posts
    3

    Question NSLookup host name to IP then ping results.

    So, here's my problem... I have several hundred host names which I have in an excel sheet, with the various server hardware information. I would like to resolve those host names into IP's then ping them, to include the response time, and status. I used a script I found on this site (see code snip below) to do the ping test, and I think it can provide the information I'd like to have

    so what I'm looking for is This:

    Column B has list of hosts
    Column C IP
    Column D Speed of response
    Column E Status
    Column F-aa (various server stats)

    
    'Summary: Pings either a local or remote cpmputer and returns the result as a string.
    '         This code uses the WMI to retrieve the information. It runs on Windows 2000
    '         2002, 2003, and XP.This code has not been tested on Windows Vista or later.
    '         The variable "Host" can be either a local or remote IP address an DNS name.
    '         SOURCE LINK: http://www.excelforum.com/excel-programming-vba-macros/705037-ping-ip-address-and-write-result-to-next-cell.html
    
    Function GetPingResult(Host)
    
       Dim objPing As Object
       Dim objStatus As Object
       Dim Result As String
    
       Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
           ExecQuery("Select * from Win32_PingStatus Where Address = '" & Host & "'")
    
       For Each objStatus In objPing
          Select Case objStatus.StatusCode
             Case 0: strResult = "Connected"
             Case 11001: strResult = "Buffer too small"
             Case 11002: strResult = "Destination net unreachable"
             Case 11003: strResult = "Destination host unreachable"
             Case 11004: strResult = "Destination protocol unreachable"
             Case 11005: strResult = "Destination port unreachable"
             Case 11006: strResult = "No resources"
             Case 11007: strResult = "Bad option"
             Case 11008: strResult = "Hardware error"
             Case 11009: strResult = "Packet too big"
             Case 11010: strResult = "Request timed out"
             Case 11011: strResult = "Bad request"
             Case 11012: strResult = "Bad route"
             Case 11013: strResult = "Time-To-Live (TTL) expired transit"
             Case 11014: strResult = "Time-To-Live (TTL) expired reassembly"
             Case 11015: strResult = "Parameter problem"
             Case 11016: strResult = "Source quench"
             Case 11017: strResult = "Option too big"
             Case 11018: strResult = "Bad destination"
             Case 11032: strResult = "Negotiating IPSEC"
             Case 11050: strResult = "General failure"
             Case Else: strResult = "Unknown host"
          End Select
          GetPingResult = strResult
       Next
    
       Set objPing = Nothing
    
    End Function
    
    
    Sub GetIPStatus()
    
      Dim Cell As Range
      Dim ipRng As Range
      Dim Result As String
      Dim Wks As Worksheet
      
        Set Wks = Worksheets("Sheet1")
        
        Set ipRng = Wks.Range("B3")
        Set RngEnd = Wks.Cells(Rows.Count, ipRng.Column).End(xlUp)
        Set ipRng = IIf(RngEnd.Row < ipRng.Row, ipRng, Wks.Range(ipRng, RngEnd))
        
          For Each Cell In ipRng
            Result = GetPingResult(Cell)
            Cell.Offset(0, 1) = Result
          Next Cell
          
    End Sub
    I'm not a programmer...
    Last edited by Elkidogz; 03-04-2013 at 04:23 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1