ASP.NET获取MAC地址与IP地址的程序浅析
ASP.NET获取MAC地址与IP地址以DNS法较为简单实用,如下:
以下是引用片段:
private void ButtonIP_Click(object sender, System.EventArgs e) { System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList; if ( addressList.Length>1) { TextLIP.Text = addressList[0].ToString(); TextSIP.Text = addressList[1].ToString(); } else { TextLIP.Text = addressList[0].ToString(); TextSIP.Text = "没有可用的连接"; } }
ASP.NET获取MAC地址与IP地址另一方法如下:
以下是引用片段:
using System.Management; string stringMAC = ""; string stringIP = ""; ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration"); ManagementObjectCollection MOC= MC.GetInstances(); foreach(ManagementObject MO in MOC) { if ((bool)MO["IPEnabled"] == true) { stringMAC += MO["MACAddress"].ToString(); TextMAC.Text = stringMAC.ToString(); string[] IPAddresses = (string[]) MO["IPAddress"]; if(IPAddresses.Length > 0) stringIP = IPAddresses[0]; TextIP.Text = stringIP.ToString(); } }
获取客户端本机的IP地址相当简易,方法如下:
以下是引用片段:
using System.Net; TextIP.Text=Page.Request.UserHostAddress;
相关推荐
Micusd 2020-11-19
cheidou 2020-11-19
星马殇 2020-11-18
Echodat 2020-10-08
flyToSkyL 2020-09-11
zjc 2020-09-03
阳光普照 2020-09-01
十年砍柴 2020-08-30
猪猪侠喜欢躲猫猫 2020-08-17
ladewang 2020-08-17
渣渣灰 2020-08-13
blankt 2020-08-15
vickay 2020-08-09
TinyDolphin 2020-08-09
山兔与孟婆 2020-08-09
longjing 2020-08-07
xiaogoua 2020-08-06