mobile.config
C# で iOS ファイルから MAC アドレスを取得したい。
誰でも方法を教えてもらえますか?
ここでは、ASP.Net C# コードを使用して iOS デバイスの MAC アドレスを見つけることができます。
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;
}
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;
}