네트워크상에 있는 장치의 네트워크정보를 볼수있는 코드

V닉맨 2014.12.11 00:28:13 *: Imports System.Net
Imports System.Net.NetworkInformation

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
getinterfaces()
End Sub

Private Sub getinterfaces()
Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()

If nics.Length < 0 Or nics Is Nothing Then
MsgBox("네트워크 인터페이스를 찾을수 없습니다")
Exit Sub
End If

ListView1.Items.Clear()

For Each netadapter As NetworkInterface In nics
Dim intproperties As IPInterfaceProperties = netadapter.GetIPProperties()
ListView1.Items.Add(netadapter.Name)

Dim paddress As PhysicalAddress = netadapter.GetPhysicalAddress()
Dim addbyte As Byte() = paddress.GetAddressBytes()
Dim macaddress As String = ""

For i = 0 To addbyte.Length - 1
macaddress &= addbyte(i).ToString("X2")

If i <> addbyte.Length - 1 Then
macaddress &= "-"
End If

Next

Dim icount As Integer = ListView1.Items.Count

Try
With ListView1.Items(icount - 1).SubItems
.Add(macaddress)
.Add(intproperties.UnicastAddresses(2).Address.ToString)
.Add(intproperties.UnicastAddresses(2).IPv4Mask.ToString)
.Add(intproperties.UnicastAddresses(0).Address.ToString)
.Add(intproperties.UnicastAddresses(1).Address.ToString)
End With

Catch ex As Exception

End Try
Next

'ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
End Sub
End Class

 

 

 

* 네트워크상에 있는 장치의 네트워크정보를 볼수있는 코드입니다

* 실행해보니 예외오류가 발생하는데...원인을 찾아 보세요

* NET Framework 4로 작성되었습니다

 

11.png

20141211-네트워크정보얻기.zip