How To Get IP Address And MAC Address Using c# , Aps.net MVC
public ActionResult Index()
{
var IP = GetUser_IP();
ViewBag.Ip = IP;
ViewBag.Mac=GetMacAddress(IP);
return View();
}
[NonAction]
protected string GetUser_IP()
{
string VisitorsIPAddr = string.Empty;
if (HttpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
VisitorsIPAddr =HttpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else if (HttpContext.Request.UserHostAddress.Length != 0)
{
VisitorsIPAddr = HttpContext.Request.UserHostAddress;
}
return VisitorsIPAddr;
}
[NonAction]
public string GetMacAddress(string ipAddress)
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
String sMacAddress = string.Empty;
foreach (NetworkInterface adapter in nics)
{
if (sMacAddress == String.Empty)// only return MAC Address from first card
{
IPInterfaceProperties properties = adapter.GetIPProperties();
sMacAddress = adapter.GetPhysicalAddress().ToString();
}
}
return sMacAddress;
}
GetMacAddress function is not working
ReplyDeleteI think MAC ADDRESS Not Returning properly let me check it , but public ip code is tested and working file
Deletehttps://www.codeproject.com/Questions/709517/How-to-get-clients-MAC-Address-in-Asp-Net
ReplyDeleteAn impressive share, I just given this onto a colleague who was doing a little evaluation on this. And he in reality bought me breakfast as a result of I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I really feel strongly about it and love studying extra on this topic. If potential, as you develop into expertise, would you mind updating your weblog with extra particulars? It’s extremely useful for me. Huge thumb up for this weblog submit! ux san francisco
ReplyDeleteI know learning the 3 new versions of IPv6 addresses sounds very confusing; believe you me, I was once in your shoes.my ip address tracker
ReplyDeleteAn IP address is a product address and intended to permit have on one organization to speak with a host on an alternate organization no matter what the kind of LANs the hosts are partaking in.https://onohosting.com/
ReplyDelete