如何从iOS手机获取MAC地址.配置文件
本文关键字:MAC 地址 配置文件 获取 手机 iOS | 更新日期: 2023-09-27 18:10:27
我想从c#中的iOS mobile.config
文件中获得MAC地址。
谁能告诉我怎么做?
在这里,我们可以使用ASP找到iOS设备的MAC地址。. Net c#代码:
var userAgent = HttpContext.Current.Request.UserAgent.ToLower(); // User's Iphone/Ipad Info.
var userAgent1 = HttpContext.Current.Request.UserHostAddress; // User's Iphone/Ipad Mac Address
GetMacAddressfromIP macadd = new GetMacAddressfromIP();
if (userAgent.Contains("iphone;"))
{
// iPhone
Label1.Text = userAgent;
Label2.Text = userAgent1;
string Getmac = macadd.GetMacAddress(userAgent1);
Label3.Text = Getmac;
}
else if (userAgent.Contains("ipad;"))
{
// iPad
Label1.Text = userAgent;
Label2.Text = userAgent1;
string Getmac = macadd.GetMacAddress(userAgent1);
Label3.Text = Getmac;
}
else
{
Label1.Text = userAgent;
Label2.Text = userAgent1;
string Getmac = macadd.GetMacAddress(userAgent1);
Label3.Text = Getmac;
}
. class
public string GetMacAddress(string ipAddress)
{
string macAddress = string.Empty;
if (!IsHostAccessible(ipAddress)) return null;
try
{
ProcessStartInfo processStartInfo = new ProcessStartInfo();
Process process = new Process();
processStartInfo.FileName = "arp";
processStartInfo.RedirectStandardInput = false;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.Arguments = "-a " + ipAddress;
processStartInfo.UseShellExecute = false;
process = Process.Start(processStartInfo);
int Counter = -1;
while (Counter <= -1)
{
Counter = macAddress.Trim().ToLower().IndexOf("mac address", 0);
if (Counter > -1)
{
break;
}
macAddress = process.StandardOutput.ReadLine();
if (macAddress != "")
{
string[] mac = macAddress.Split(' ');
if (Array.IndexOf(mac, ipAddress) > -1)
{
if (mac[11] != "")
{
macAddress = mac[11].ToString();
break;
}
}
}
}
process.WaitForExit();
macAddress = macAddress.Trim();
}
catch (Exception e)
{
Console.WriteLine("Failed because:" + e.ToString());
}
return macAddress;
}