用C#編寫獲取遠程IP,MAC的方法
更新時間:2007年04月16日 00:00:00 作者:
如果要想獲得遠程的地址,需要用sendarp這個函數(shù)來實現(xiàn)。具體的代碼如下:
[DllImport("Iphlpapi.dll")]
private static unsafe extern int SendARP(Int32 dest,Int32 host,ref IntPtr mac,ref IntPtr length);
[DllImport("Ws2_32.dll")]
private static extern Int32 inet_addr(string ip);
Int32 ldest= inet_addr("157.60.68.163");//目的地的ip
Int32 lhost= inet_addr("157.60.68.33");//本地的ip
try
{
Byte[] macinfo=new Byte[6];
Int32 length=6;
IntPtr mac=new IntPtr(macinfo[0]);
IntPtr len=new IntPtr(6);
int ii=SendARP(ldest,lhost, ref mac, ref len);
Console.WriteLine("Mac Add:"+mac);
Console.WriteLine("length:"+len);
}
catch(Exception err)
{
Console.WriteLine(err);
}
[DllImport("Iphlpapi.dll")]
private static unsafe extern int SendARP(Int32 dest,Int32 host,ref IntPtr mac,ref IntPtr length);
[DllImport("Ws2_32.dll")]
private static extern Int32 inet_addr(string ip);
Int32 ldest= inet_addr("157.60.68.163");//目的地的ip
Int32 lhost= inet_addr("157.60.68.33");//本地的ip
try
{
Byte[] macinfo=new Byte[6];
Int32 length=6;
IntPtr mac=new IntPtr(macinfo[0]);
IntPtr len=new IntPtr(6);
int ii=SendARP(ldest,lhost, ref mac, ref len);
Console.WriteLine("Mac Add:"+mac);
Console.WriteLine("length:"+len);
}
catch(Exception err)
{
Console.WriteLine(err);
}
相關文章
C#調(diào)用RabbitMQ實現(xiàn)消息隊列的示例代碼
這篇文章主要介紹了C#調(diào)用RabbitMQ實現(xiàn)消息隊列的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-12-12
c#只讀字段和常量的區(qū)別,以及靜態(tài)構造函數(shù)的使用實例
這篇文章主要介紹了c#只讀字段和常量的區(qū)別,以及靜態(tài)構造函數(shù)的使用實例,有需要的朋友可以參考一下2013-12-12
C#實現(xiàn)在Form里面內(nèi)嵌dos窗體的方法
這篇文章主要介紹了C#實現(xiàn)在Form里面內(nèi)嵌dos窗體的方法,涉及C#針對Form窗體的設置及使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-09-09

