Finding IP Address through Visual Basic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VijaySofist
    New Member
    • Jun 2007
    • 107

    #1

    Finding IP Address through Visual Basic

    Hai!

    I need to find out the IP Address of any System thro Visual Basic 6.0 by using the Drive Letter (If it is mapped in my System).

    Can anybody Help me in solving the problem
  • danp129
    Recognized Expert Contributor
    • Jul 2006
    • 323

    #2
    I made this in VBScript, there are better ways to get an IP from a hostname using VB6 but it will work.

    [CODE=vb]
    Private Sub Command1_Click( )
    Dim fs 'As FileSystemObjec t
    Dim dc 'As Drives
    Dim oDrive 'As Drive
    Dim arTmp
    Dim sIP
    Set fs = CreateObject("S cripting.FileSy stemObject")
    Set dc = fs.Drives

    For Each oDrive In dc
    If oDrive.DriveTyp e = 3 Then
    arTmp = Split(oDrive.Sh areName, "\")
    If UBound(arTmp) >= 2 Then
    'Get the IP address
    sIP = GetIP(arTmp(2), 1)
    Debug.Print "Drive '" & oDrive.DriveLet ter & "' on '" & arTmp(2) & "' uses IP: " & sIP
    End If
    End If
    Next 'oDrive

    Set fs = Nothing
    Set dc = Nothing
    End Sub

    Function GetIP(sHost, iTimeoutMs)
    'Returns IP, or 0 if unavailable
    Dim png
    Dim sPing
    Dim arTmp
    Dim WshShell

    Set WshShell = CreateObject("W Script.Shell")
    Set png = WshShell.exec(" ping -n 1 -w " & iTimeoutMs & " " & sHost)

    Do Until png.Status = 1: DoEvents: Loop

    sPing = LCase(png.stdou t.readall)
    arTmp = Split(sPing, "ping statistics for ")

    If UBound(arTmp) > 0 Then
    'stats available
    GetIP = Left(arTmp(1), InStr(1, arTmp(1), ":") - 1)
    Else
    GetIP = 0
    End If
    set WshShell = Nothing
    End Function[/CODE]

    Comment

    • VijaySofist
      New Member
      • Jun 2007
      • 107

      #3
      Hai!

      Thank You for the Solution. But It does n't working. Can you please send me the Steps for Running this code.


      Thanks in Regards.
      By Vijay

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        If you want to use this code in VB6, you'll have to add "Microsoft Scripting Runtime" in the project references.

        Comment

        Working...