用C#編寫(xiě)獲取遠(yuǎn)程IP,MAC的方法
更新時(shí)間:2007年04月16日 00:00:00 作者:
如果要想獲得遠(yuǎn)程的地址,需要用sendarp這個(gè)函數(shù)來(lái)實(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);
}
相關(guān)文章
C#實(shí)現(xiàn)判斷操作系統(tǒng)是否為Win8以上版本
這篇文章主要介紹了C#實(shí)現(xiàn)判斷操作系統(tǒng)是否為Win8以上版本,本文講解了利用C#獲取OS的版本號(hào)、利用反射獲取當(dāng)前正在運(yùn)行的程序的版本信息、 利用C#判斷當(dāng)前操作系統(tǒng)是否為Win8系統(tǒng)等內(nèi)容,需要的朋友可以參考下2015-06-06C#獲得MAC地址(網(wǎng)卡序列號(hào))的實(shí)現(xiàn)代碼
這篇文章主要介紹了C#獲得MAC地址的實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-02-02C#實(shí)現(xiàn)XSL轉(zhuǎn)換的方法
這篇文章主要介紹了C#實(shí)現(xiàn)XSL轉(zhuǎn)換的方法,結(jié)合實(shí)例分析了C#執(zhí)行XSL轉(zhuǎn)換XML的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11C#?Timer控件學(xué)習(xí)之使用Timer解決按鈕冪等性問(wèn)題
Timer控件又稱(chēng)定時(shí)器控件或計(jì)時(shí)器控件,該控件的主要作用是按一定的時(shí)間間隔周期性地觸發(fā)一個(gè)名為T(mén)ick的事件,因此在該事件的代碼中可以放置一些需要每隔一段時(shí)間重復(fù)執(zhí)行的程序段,這篇文章主要介紹了關(guān)于C#使用Timer解決按鈕冪等性問(wèn)題的相關(guān)資料,需要的朋友可以參考下2022-10-10WinForm實(shí)現(xiàn)為T(mén)extBox設(shè)置水印文字功能
這篇文章主要介紹了WinForm實(shí)現(xiàn)為T(mén)extBox設(shè)置水印文字功能,很實(shí)用的一個(gè)技巧,需要的朋友可以參考下2014-08-08