+ Reply to Thread
Results 1 to 2 of 2

Get IP address for a remote computer based on its hostname

  1. #1
    stabilo
    Guest

    Get IP address for a remote computer based on its hostname

    I'd like to get, with VBA, the IP address(es) if a computer based on its
    hostname :

    eg. Cell "a1" = PCXXX
    Cell "a2" = XX.XX.XX.XX

    I have seen some example that put the result of a ping into a text file,
    then pars this text file and put in cells the ip address into a cell.

    Is there another way ? I'm using Excel 2003

  2. #2
    sebastienm
    Guest

    RE: Get IP address for a remote computer based on its hostname

    Hi
    try:
    '----------------------------------------
    Sub test()
    Dim v As Variant
    Dim Filename As String, f As String
    Dim ip As String

    Filename = "E:\iptemp"
    'Create command file
    f = CreateCommandFile(Filename, "www.yahoo.com")
    'run the command in silent mode
    Shell f, vbHide
    'get info from output file
    v = GetIpInfo(Filename & ".txt")
    MsgBox v

    'add code here to delete files
    End Sub

    'Creates a .bat file containing ping. Output into file FileName & ".txt"
    Function CreateCommandFile(Filename As String, ip As String)
    Dim n As Long, File As String, s As String

    File = Filename & ".bat"
    s = "ping " & ip & " >" & Filename & ".txt"
    n = FreeFile()

    Open File For Output Access Write As #n
    Print #n, s
    Close #n

    CreateCommandFile = File
    End Function

    'Get ip info
    ' need to add code in case of no reply during the ping
    Function GetIpInfo(Filename As String)
    Dim n As Long, s As String

    n = FreeFile()
    Open Filename For Input Access Read As #n
    Line Input #n, s
    Line Input #n, s
    Line Input #n, s 'data on third row
    Close #n

    'extract info within the 2 brackets [ ] of text file
    n = Strings.InStr(s, "[")
    s = Strings.Right(s, Len(s) - n)
    n = Strings.InStr(s, "]")
    s = Strings.Left(s, n - 1)

    GetIpInfo = s
    End Function
    '---------------------------------------------------------
    --
    Regards,
    Sébastien
    <http://www.ondemandanalysis.com>


    "stabilo" wrote:

    > I'd like to get, with VBA, the IP address(es) if a computer based on its
    > hostname :
    >
    > eg. Cell "a1" = PCXXX
    > Cell "a2" = XX.XX.XX.XX
    >
    > I have seen some example that put the result of a ping into a text file,
    > then pars this text file and put in cells the ip address into a cell.
    >
    > Is there another way ? I'm using Excel 2003


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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