關於對IP的一些操作

2021-04-12 18:16:51 字數 2401 閱讀 7529

最近看到一些對ip的操作,感覺不錯,而且以後可能會用到,所以收集過來,以備以後使用.

1.獲取mac位址操作:

using   system;  

using   system.runtime.interopservices;  

namespace   utilitycontrol  

[dllimport("iphlpapi.dll")]  

private   static   extern   int   sendarp(int32   dest,int32   host,ref   int64   mac,ref   int32   length);  

[dllimport("ws2_32.dll")]    

private   static   extern   int32   inet_addr(string   ip);  

///  

///   根據ip得到網絡卡mac位址  

///  

///   給出的ip位址

///   對應ip的網絡卡mac位址

public   static   int64   getmacbyip(string   ip)    

catch(exception   err)    

",err.message);    

}    

return   0;    

}    

}  

}  

用c#編寫獲取遠端ip,mac的方法

[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

trycatch(exception  err)

用wmi

使用時首先新增system.management.dll,然後引用

using system.management;

using system.threading; }

2.手動設定ip或設定動態ip

如果是winform的話,需要新增對system.management.dll的引用

然後使用下面的類就可以實現你的前2個要求:

namespace modify

; /// string subnetlist = new string;

/// o.changeto(iplist,subnetlist);

//////

public changeip()

/// cortrol

/// ipaddr list

/// subnetmask list

public void changeto(string ipaddr, string subnetmask)

}/// cortrol

/// ipaddr list

/// subnetmask list

/// gateway list

/// gateway costmetric list, example: 1

public void changeto(string ipaddr, string subnetmask, string gateways, string gatewaycostmetric)

}/// cortrol

/// ipaddr list

/// subnetmask list

/// gateway list

/// gateway costmetric list, example: 1

/// dnsserver list

public void changeto(string ipaddr, string subnetmask, string gateways, string gatewaycostmetric, string dnsserver)

}/// dhcpenabled

public void enabledhcp()}}

}}messagebox.show("ip已經更改,請驗證");

//對第乙個問題的驗證,如果ip可用,當前並不是自動獲取ip,這時下面的方法會自動獲取ip

test.enabledhcp();}}

}

關於tomcat的一些操作

參考 先感謝這位兄弟的整理,感覺很有用,這裡自己也借用一下 1.tomcat原來的預設根目錄是http localhost 8080,如果想修改訪問的根目錄,可以這樣 找到tomcat的server.xml 在conf目錄下 找到 如下 unpackwars true autodeploy true...

關於檔案的一些操作

今天遇到一些關於檔案的知識點 codeblocks16.0裡面不支援 include只有 include使用時要把std包包含在裡面 using namespace std 而vc6.0卻不能使用這個包 下面是課件上的一些知識點,以後用到的時候再拿出來看看吧 include void main in...

關於日誌的一些操作

常用的系統日誌如下 核心啟動日誌 var log dmesg 系統報錯日誌 var log messages 郵件系統日誌 var log maillog ftp系統日誌 var log xferlog 安全資訊和系統登入與網路連線的資訊 bar log secure 登入記錄 var log wt...