c#获取ip地址 -凯发k8官方网
获得公网ip
private string getclientip()
{
string result = httpcontext.current.request.servervariables["http_x_forwarded_for"];
if (null == result || result == string.empty)
{
result = httpcontext.current.request.servervariables["remote_addr"];
}
if (null == result || result == string.empty)
{
result = httpcontext.current.request.userhostaddress;
}
return result;
}
获得局域网ip:
string ipaddr = dns.gethostentry(dns.gethostname()).addresslist[2].tostring();
转载于:https://www.cnblogs.com/xsj1989/p/5509871.html
总结
- 上一篇:
- 下一篇: