代码之家  ›  专栏  ›  技术社区  ›  volody

如何在Windows XP中编程创建静态ARP缓存项

  •  3
  • volody  · 技术社区  · 14 年前

    我发现的唯一方法是 阿普 Address Resolution Protocol

    添加了 命令未从缓存过期。

    有相关帖子 How do I access ARP-protocol information through .NET?

    3 回复  |  直到 7 年前
        1
  •  0
  •   Zach Burlingame    14 年前

    显然,它不是纯粹的.NET,但是您应该能够通过IP帮助程序API库中的Win32API来实现,即CreateIpNetEntry和SetIpNetEntry方法。您可能希望通过p/UnjKE或包管理的C++库来实现这一点。

    http://msdn.microsoft.com/en-us/library/aa366071(v=vs.85).aspx

        2
  •  0
  •   volody    14 年前

    我现在使用的简单解决方案是运行批处理命令,将这个静态条目添加到ARP表中。在Vista和更高版本上,这需要管理员用户权限。

    ' arp -s 192.168.1.12 01-02-03-04-05-06
    Public Sub UpdateArpTable(IpAddress as string, MacAddress as string)
        Dim outputMessage As string = ""
        Dim errorMessage As string = ""
        Dim command As String = String.Format("-s {0} {1}", Address, MacAddress)
        ExecuteShellCommand("arp", command, outputMessage, errorMessage)
    End Sub
    
    
    Public Shared Sub ExecuteShellCommand(FileToExecute As String, CommandLine As String)
        Dim Process As System.Diagnostics.Process = Nothing
        Try
            Process = New System.Diagnostics.Process()
            Dim CMDProcess As String = String.Format("{0}\cmd.exe", Environment.SystemDirectory)
    
            Dim Arguments As String = String.Format("/C {0}", FileToExecute)
    
            If CommandLine IsNot Nothing AndAlso CommandLine.Length > 0 Then
                Arguments += String.Format(" {0}", CommandLine)
            End If
            Dim ProcessStartInfo As New System.Diagnostics.ProcessStartInfo(CMDProcess, Arguments)
            ProcessStartInfo.CreateNoWindow = True
            ProcessStartInfo.UseShellExecute = False
            ProcessStartInfo.RedirectStandardOutput = True
            ProcessStartInfo.RedirectStandardInput = True
            ProcessStartInfo.RedirectStandardError = True
            Process.StartInfo = ProcessStartInfo
    
            Process.Start()
            Process.WaitForExit()
            Process.WaitForExit()
        Finally
            ' close process and do cleanup
            Process.Close()
            Process.Dispose()
            Process = Nothing
        End Try
    End Sub
    
        3
  •  0
  •   Orestis P.    11 年前

      Process process = new Process();
      process.StartInfo.FileName = "arp -s 220.0.0.161 00-50-04-62-F7-23";
      process.StartInfo.CreateNoWindow = true; //Don't show window
      process.Start();