我正在开发一个VB.net Windows窗体应用程序。我的应用程序连接到网络上的指定计算机名称并获取其MAC地址并执行检查,以防止将该应用程序用于“外出”。
Mainpage加载事件如下:
Private Declare Function inet_addr Lib "wsock32.dll" (ByVal s As String) As Integer
Private Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As Integer, ByVal SrcIP As Integer, ByRef pMACAddr As Integer, ByRef PhyAddrLen As Integer) As Integer
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef dst As Byte, ByRef src As Integer, ByVal bcount As Integer)
Private Sub Mainpage_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim ServerName = "Office-NAS"
Dim IpCollection As New Collection
Try
Dim ipE As Net.IPHostEntry = System.Net.Dns.GetHostEntry(ServerName)
Dim IpA() As Net.IPAddress = ipE.AddressList
For i = 0 To IpA.GetUpperBound(0)
IpCollection.Add(IpA(i).ToString)
Next
Catch
MessageBox.Show("Not connected to server - exiting")
Me.Close()
End Try
Dim sip As String = IpCollection(1)
Dim inet As Integer
Dim b(6) As Byte
Dim pMACAddr As Integer
Dim j As Short
Dim sResult As String = ""
inet = inet_addr(sip)
If SendARP(inet, 0, pMACAddr, 6) = 0 Then
CopyMemory(b(0), pMACAddr, 6)
For j = 0 To 5
sResult = sResult & Microsoft.VisualBasic.Right("0" & Hex(b(j)), 2)
If j < 5 Then sResult &= "-"
Next
End If
MessageBox.Show(sResult) '' The server's MAC address
Dim MACToBeChecked As String = "00-11-32-2E-93-76"
Stop
If sResult <> MACToBeChecked Then
MessageBox.Show("Not in office- Exiting")
Me.Close()
End If
'Some other stuff
End Sub
我没有写过获取IP地址和获取MAC地址部分,我在网上找到了它们。他们的工作非常完美!
现在,我还想使用混淆器来使我的代码更难以反编译。我正在使用Eazfuscator.NET。它工作正常,但是当我使用它时,上面的代码不起作用。我意识到当混淆打开时,无法正确获取服务器MAC地址。实际上,前4对字符是正确的,但最后2对是错误的!所以我无法正确地进行检查。
我很困惑并坚持这个问题。我会感激任何帮助。