: 공공 IP 주소에 대한
string ip = System.Web.HttpContext.Current.Request.UserHostAddress;
:
public static string GetPublicIP()
{
string url = "http://checkip.dyndns.org";
System.Net.WebRequest req = System.Net.WebRequest.Create(url);
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
string response = sr.ReadToEnd().Trim();
string[] a = response.Split(':');
string a2 = a[1].Substring(1);
string[] a3 = a2.Split('<');
string a4 = a3[0];
return a4;
}
또는 MAC 주소를
private string GetPublicIpAddress()
{
var request = (HttpWebRequest)WebRequest.Create("http://ifconfig.me");
request.UserAgent = "curl"; // this simulate curl linux command
string publicIPAddress;
request.Method = "GET";
using (WebResponse response = request.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
publicIPAddress = reader.ReadToEnd();
}
}
return publicIPAddress.Replace("\n", "");
}
:
public string GetMACAddress()
{
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;
}
시도해보십시오. 도움이 될 수 있습니다.
같은 Lan에 있다면 Lan IP 주소 만 가져올 수 있습니다. 마찬가지로 인터넷 기반 서비스는 인터넷을 통해 액세스하기 때문에 공개 IP 주소 만 볼 수 있습니다. 동일한 네트워크 링크에 있다면 MAC 주소 만 볼 수 있습니다. 당신은 완전히 다른 수준에서 작동하는 3 가지 정보 조각을 요구하고 있습니다. 실제 문제는 무엇을 해결하려고합니까? –
[의견] (http://stackoverflow.com/questions/21751402/get-public-ip-address-lan-ip-address-mac-address-of-clients-machine-in-mvc-4#comment32901883_21751542)) "방문자를 고유하게 식별하는 방법"을 묻는 질문은 _이 질문이 [ASP.NET 응용 프로그램에서 클라이언트 컴퓨터를 고유하게 식별하는 방법]과 같은 질문이라고 말하고 싶습니다. (http://stackoverflow.com/questions/4609316/how-to-uniquely-identify-the-client-machine-in-asp-net-application)을 참조하십시오. – CodeCaster