Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# “如何获取网络计算机名和网络IP”;不是互联网IP“;在Asp.Net中_C#_Asp.net_Ip - Fatal编程技术网

C# “如何获取网络计算机名和网络IP”;不是互联网IP“;在Asp.Net中

C# “如何获取网络计算机名和网络IP”;不是互联网IP“;在Asp.Net中,c#,asp.net,ip,C#,Asp.net,Ip,因为我要创建维护请求页面,所以任何员工都可以在没有internet的情况下从本地网络使用此页面,我想获取发出请求的计算机名和Ip 我搜索并阅读了这篇文章,但如果我得到的是:如何获取internet ip或主机名和ip,那么我的问题是“如何在Asp.Net中获取网络计算机名和网络ip”而不是“internet ip” 我发现有关Internet Ip和主机信息的一些信息是: using System.Net; //Get the Host name: string strHostName

因为我要创建维护请求页面,所以任何员工都可以在没有internet的情况下从本地网络使用此页面,我想获取发出请求的计算机名和Ip

我搜索并阅读了这篇文章,但如果我得到的是:如何获取internet ip或主机名和ip,那么我的问题是“如何在Asp.Net中获取网络计算机名和网络ip”而不是“internet ip”

我发现有关Internet Ip和主机信息的一些信息是:

using System.Net;
//Get the Host name:

    string strHostName = string.Empty;
    strHostName = Dns.GetHostName();

    // Then using host name, get the IP address list..
    IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
    //Get the IP address
    IPAddress[] addr = ipEntry.AddressList;
    for (int i = 0; i < addr.Length; i++)
    {
        Response.Write("IP Address {0}: {1} " + i + addr[i].ToString() + ", HostName: " + strHostName);
    } 
    // end of host info.
使用System.Net;
//获取主机名:
string strHostName=string.Empty;
strHostName=Dns.GetHostName();
//然后使用主机名获取IP地址列表。。
IPHostEntry ipEntry=Dns.GetHostByName(strHostName);
//获取IP地址
IPAddress[]addr=ipEntry.AddressList;
for(int i=0;i
互联网信息的这种方式:

Response.Write("Your IP Address: " + Request.UserHostAddress + "<BR>");
Response.Write("Your Computer Name: " + System.Net.Dns.GetHostEntry(Request.UserHostAddress).HostName);
Response.Write(“您的IP地址:+Request.UserHostAddress+””
”; 写(“您的计算机名:”+System.Net.Dns.GetHostEntry(Request.UserHostAddress.HostName));

那么,有没有办法获取本地Ip和计算机名???

如果您正确配置了DNS,以便在计算机连接和断开连接时使用计算机名进行更新,那么您可以使用反向解析从客户端Ip地址获取回主机名


如果您的网站位于防火墙内,则连接的用户主机地址将是内部地址,并且可以解析。如果站点位于外部(或可能位于DMZ内),则在不要求用户提供名称的情况下,或者通过在客户端上运行一些可信代码来访问本地信息,您将无法获取该名称。

您所说的“本地IP”和“网络计算机名”是什么意思?您输入的代码是正确的:您需要
Dns.GetHostName()
。请记住,NetBIOS名称在今天并不重要,127.0.0.1始终是“本地”IP地址。您的机器是多主机还是在Internet和专用网络上同时运行?我的意思是:我们的员工将使用此页面作为内部网络,正如您所知,每台计算机都有内部ip,而不是公共Internet ip,我们网络中的每台计算机都有部门名称,所以我想获得内部ip和计算机名称,以便在维护中使用。