在Asp.net中获取本地IP地址 [英] Get Local IP Address in Asp.net

查看:191
本文介绍了在Asp.net中获取本地IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Asp.net获取本地IP地址,



i使用以下代码



  string  GetIP4Address()
{
string IP4Address = String .Empty;


foreach (IP地址IPA Dns.GetHostAddresses(Dns) .GetHostName()))
{
if (IPA.AddressFamily.ToString()== InterNetwork
{
IP4Address = IPA.ToString();
break ;
}
}
return IP4Address;
}





此函数返回192.168.1.104



但当我把它放在FTP服务器,然后它给另一个IP:10.10.122.147

所以我想得到我的本地IP地址(通过 ipconfig显示命令pront 命令)在asp.net网站上的FTP服务器,



显示的一个演示URL:http://www.ipaddresslocation.org/ [ ^ ]

解决方案

在这个论坛上搜索一下:如何将公共IP地址分配给私人IP地址 [ ^ ]


TextBox1.Text = System.Ne t.Dns.GetHostEntry(System.Net.Dns.GetHostName())AddressList.GetValue(0)的ToString();

How to get local IP address in Asp.net,

i Have used the below code

string GetIP4Address()
    {
        string IP4Address = String.Empty;

       
        foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
        {
            if (IPA.AddressFamily.ToString() == "InterNetwork")
            {
                IP4Address = IPA.ToString();     
                break;
            }           
        }
        return IP4Address;
    }



this function returns 192.168.1.104

but when i place it in FTP server, then it is giving another IP: 10.10.122.147
so i want to get my local ip address(which is displaying in command pront by ipconfig command) in asp.net website which is in FTP server,

One demo URL where it is displaying : http://www.ipaddresslocation.org/[^]

解决方案

with a little search on this forum: how to assign public to private ip address[^]


TextBox1.Text = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.GetValue(0).ToString();


这篇关于在Asp.net中获取本地IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆