2010-10-08 2 views

Répondre

0

Il ne serait pas purement .NET évidemment, mais vous devriez être en mesure de le faire via l'API Win32 dans la bibliothèque API d'assistance IP - à savoir la CreateIpNetEntry et les méthodes de SetIpNetEntry. Vous voudrez probablement le faire via P/Invoke ou une bibliothèque C++ gérée.

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

0

La solution simple J'utilise est en ce moment à exécuter la commande de lot qui ajoutera cette entrée statique dans la table ARP. Sur Vista et plus, cela nécessitera des droits d'administrateur.

' 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 
0

Vous pouvez simplement exécuter la commande ARP -s inet_addr eth_adr où inet_addr est l'adresse IP et eth_adr est l'adresse matérielle.

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(); 
Questions connexes