台式电脑

电脑上怎么样使用ip函数(c#得到本机IP的函数)

收集客户机信息时,需要得到客户机的IP,那么客户端就需要提供自己的本机IP:

usingSystem;usingSystem.Net;usingSystem.Windows.Forms;namespaceMynet{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){MessageBox.Show(GetMyIP());}///

///得到本机IP//////publicstringGetMyIP(){try{stringcomputername=Dns.GetHostName();IPHostEntryipall=Dns.GetHostEntry(computername);for(inti=0;i< ipall.AddressList.Length; i++) { string theip = ipall.AddressList[i].ToString(); if (theip.LastIndexOf(".") != -1) { return theip; } } return "未得到IP地址"; } catch (Exception ErrMsg) { return ErrMsg.ToString(); } } }}

电脑上怎么样使用ip函数(c#得到本机IP的函数)

相关新闻

返回顶部