반응형

* VBNET API를 이용한 NetworkNetwork MacAddress (네트워크 맥 주소 구하기) 예제...

 

 

전체 소스 코드

Form1.vb

 

Public Class Form1


    Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As UInt32, ByVal SrcIP As UInt32, _
      ByVal pMacAddr As Byte(), ByRef PhyAddrLen As Integer) As Integer

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        MessageBox.Show(Get_MACAddress("192.168.0.6"))

    End Sub


    Private Function Get_MACAddress(ByVal strIPAddress As String) As String
        Dim ip As Net.IPAddress = Net.IPAddress.Parse(strIPAddress)

        Dim btIPArray() As Byte = New Byte(6) {}

        Dim uiIP As System.UInt32 = CType(btIPArray.Length, System.UInt32)

        Dim iIPValue As Integer = BitConverter.ToInt32(ip.GetAddressBytes(), 0)

        Dim iReturnCode As Integer = SendARP(iIPValue, 0, btIPArray, uiIP)

        If iReturnCode <> 0 Then
            Return ""
        End If

        Dim strIP(Convert.ToInt32(uiIP)) As String

        Dim i As Integer
        For i = 0 To uiIP - 1 Step i + 1
            strIP(i) = btIPArray(i).ToString("X2")
        Next
        Dim strMacAddress As String = String.Join(":", strIP)
        Return strMacAddress
    End Function

End Class

*예제 결과 확인

 

 

어댑터 설정 변경 - > 해당 어댑터 더블 클릭 - > 자세히 버튼을 클릭 하여 맥주소를 확인 



https://kdsoft-zeros.tistory.com/143

 

[C#] IP MacAddress (IP 맥 주소 구하기)

* C# IP MacAddress 구하기 예제... 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; us..

kdsoft-zeros.tistory.com

 

반응형

+ Recent posts