Get IP Address

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason

    #1

    Get IP Address

    Hello

    I've 4 nic's in my pc, and through the code beloew I'm able to get mac
    address of the nic that I want. now how do I get the IP address of that
    NIC?

    Dim MacAddress As String
    Dim scope As ManagementScope = New
    ManagementScope (ManagementPath .DefaultPath)
    Dim query As SelectQuery = New
    SelectQuery("Wi n32_NetworkAdap terConfiguratio n")
    ' this query returns all properties of the class
    Dim searcher As ManagementObjec tSearcher = New
    ManagementObjec tSearcher(scope , query)
    Dim mo As New ManagementObjec t
    For Each mo In searcher.Get()
    If (mo.Item("Capti on").ToString ) = "[00000016] Packet Scheduler
    Miniport" Then
    Try
    MacAddress = (mo.Item("MacAd dress").ToStrin g)
    Me.RichTextBox1 .Text &= "Mac Address: " & MacAttack &
    vbCrLf
    Catch ex As Exception

    End Try
    End If
    Next


    Thanks



  • Josef Brunner

    #2
    Re: Get IP Address

    Hi,

    this function will give you the IP of the "first" nic

    Private Function GetIP() As String

    Dim ComputerName As String = System.Net.Dns. GetHostName

    Dim Host As System.Net.IPHo stEntry

    Dim HostAddresses() As System.Net.IPAd dress

    Host = System.Net.Dns. GetHostEntry(Co mputerName)

    HostAddresses = Host.AddressLis t

    Return HostAddresses(0 ).ToString

    End Function



    All IPs are within "HostAddres ses"



    Hope this helped,

    Josef

    "Jason" <jason@someone. com> schrieb im Newsbeitrag
    news:%23PSM1%23 iNGHA.1028@TK2M SFTNGP11.phx.gb l...[color=blue]
    > Hello
    >
    > I've 4 nic's in my pc, and through the code beloew I'm able to get mac
    > address of the nic that I want. now how do I get the IP address of that
    > NIC?
    >
    > Dim MacAddress As String
    > Dim scope As ManagementScope = New
    > ManagementScope (ManagementPath .DefaultPath)
    > Dim query As SelectQuery = New
    > SelectQuery("Wi n32_NetworkAdap terConfiguratio n")
    > ' this query returns all properties of the class
    > Dim searcher As ManagementObjec tSearcher = New
    > ManagementObjec tSearcher(scope , query)
    > Dim mo As New ManagementObjec t
    > For Each mo In searcher.Get()
    > If (mo.Item("Capti on").ToString ) = "[00000016] Packet Scheduler
    > Miniport" Then
    > Try
    > MacAddress = (mo.Item("MacAd dress").ToStrin g)
    > Me.RichTextBox1 .Text &= "Mac Address: " & MacAttack &
    > vbCrLf
    > Catch ex As Exception
    >
    > End Try
    > End If
    > Next
    >
    >
    > Thanks
    >
    >
    >[/color]


    Comment

    • Simon Says

      #3
      Re: Get IP Address

      If you are using VB 2005, you could try this:

      ///
      Imports System.Net.Netw orkInformation

      Dim allInterfaces() as NetworkInterfac e
      Dim aInterface as NetworkInterfac e

      allInterfaces = NetworkInterfac e.GetAllNetwork INterfaces()

      For Each aInterface In allInterfaces
      Dim ipAddress as String =
      aInterface.GetI PProperties.Uni castAddresses(0 ).Address.ToStr ing
      Dim macAdd as String = aInterface.GetP hysicalAddress. ToString
      Next
      //

      Hope it helps.

      --Simon


      "Jason" <jason@someone. com> wrote in message
      news:%23PSM1%23 iNGHA.1028@TK2M SFTNGP11.phx.gb l...[color=blue]
      > Hello
      >
      > I've 4 nic's in my pc, and through the code beloew I'm able to get mac
      > address of the nic that I want. now how do I get the IP address of that
      > NIC?
      >
      > Dim MacAddress As String
      > Dim scope As ManagementScope = New
      > ManagementScope (ManagementPath .DefaultPath)
      > Dim query As SelectQuery = New
      > SelectQuery("Wi n32_NetworkAdap terConfiguratio n")
      > ' this query returns all properties of the class
      > Dim searcher As ManagementObjec tSearcher = New
      > ManagementObjec tSearcher(scope , query)
      > Dim mo As New ManagementObjec t
      > For Each mo In searcher.Get()
      > If (mo.Item("Capti on").ToString ) = "[00000016] Packet Scheduler
      > Miniport" Then
      > Try
      > MacAddress = (mo.Item("MacAd dress").ToStrin g)
      > Me.RichTextBox1 .Text &= "Mac Address: " & MacAttack &
      > vbCrLf
      > Catch ex As Exception
      >
      > End Try
      > End If
      > Next
      >
      >
      > Thanks
      >
      >
      >[/color]


      Comment

      Working...