獲取伺服器ip,本地ip,本在mac

2021-06-02 13:50:13 字數 1179 閱讀 3408

using system.net;

// 在此處放置使用者**以初始化頁面

string strhostname = dns.gethostname(); //得到本機的主機名

iphostentry ipentry = dns.gethostbyname(strhostname); //取得本機ip 

sessionid = sessionid +","+ ipentry.addresslist[0].tostring();

label1.text = sessionid;

system.diagnostics.process p=new system.diagnostics.process();

p.startinfo.createnowindow=true;

p.startinfo.useshellexecute=false;

p.startinfo.redirectstandardoutput=true;

p.startinfo.filename="ipconfig";

p.startinfo.arguments="/all";

p.start();

p.waitforexit();

string s=p.standardoutput.readtoend();

label1.text+=","+s.substring(s.indexof("physical address. . . . . . . . . :")+36,17);

------------------------

////獲取指定網域名稱的ip位址

//string stringurl;

stringurl = "";

for (int i = 0; i < dns.gethostentry(stringurl).addresslist.length; i = i + 1) //

//獲取本機ip位址

//string stringhost;

stringhost = dns.gethostname();

for (int i = 0; i < dns.gethostentry(stringhost).addresslist.length; i = i + 1)

伺服器獲取本地Ip位址

string getlocalip char buff bufsiz struct ifconf conf conf.ifc len bufsiz conf.ifc buf buff const int s socket pf inet,sock dgram,0 ioctl s,siocgifcon...

java獲取本地IP和伺服器IP

string address inetaddress.getlocalhost gethostaddress tostring 這種方法能不能在linux伺服器上直接獲取ip有待驗證 設定異常資訊 param t 異常資訊。注意 這裡使用的是throwable來接收引數,為什麼不是使用excepti...

獲取本地Mac位址,伺服器IP,及驗證

獲取本地mac位址 public string getmac using system.management.managementclass mc new system.management.managementclass win32 networkadapterconfiguration syst...