C #get localIPAddress andMACAddress 1, obtain the LAN IP address through the host name; try { iphostentry iphostentry = Dns.gethostentry (Txthost.text);//pass Computer name if (ipHostEntry.Aliases.Length > 0) { foreach (string Alias in iphostentry.aliases) txtip.text = alias; } //Get IP address foreach (IPAddress addr in iphostentry.addresslist) Txtipaddress.text = addr. ToString ();//Get IP address } Catch { MessageBox.Show ("Wrong host name.") "); } 2, get host name via LAN IP address; try { iphostentry iphostentry = dns.gethostbyaddress (Txtip.text); ;//Pass IP address txthostname.text = IpHostEntry.HostName.ToString ()//Get host name } Catch { MessageBox.Show ("Wrong IP Address"). "); } 3, get MAC address public static string Readmac via LAN IP address (string IP)//IP address, you can return the MAC address { string mac = ""; System.Diagnostics.Process p = new System.Diagnostics.Process (); p.startinfo.filename = "nbtstat"; p.startinfo.arguments = "-a" + IP; P.startinfo.useshellexecute = false; P.startinfo.createnowindow = true; P.startinfo.redirectstandardoutput = true; P.start (); string output = P.standardoutput.readtoend (); int len = output. IndexOf ("MAC address ="); if (len>0) { & NBsp; mac = output. Substring (len + 14, 17); } p.WaitForExit ( ); return mac; }
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.