如何在Winform中获取出本机对外的Ip,不是内网的Ip,请各位看看怎么弄呢
解决方案 »
- 关于UpdatePanel与Redirect的困扰。请大神指点
- 400 Bad Request
- listviewitem 改变背景颜色问题。
- C#是否有逻辑事务处理?如何用?
- 高手大侠帮忙!
- # 如何将Image类型转换为 string 类型, 在sql的字符串中imgName 附近报错是什么原因,在数据库中imgName是Image类型,
- C#无法调用OCX控件,哪位大牛帮看看!
- [分享]DataWindow.net做成自定义控件
- 很着急啊,请教了!请问如果一个服务器有多个IP,然后在IIS中建立了一个自己的虚拟目录,如何能够得到和我建立的虚拟目录相关的那个IP地
- 能否告诉一下关于C#方面的经典的书?
- 关于Visual Sourcesafe 2005 internet迁出问题
- UltraWebGrid
Response.Write(Request.ServerVariables("REMOTE_ADDR"))
Response.End
%>保存成 ip.asp然后用iis建一个网站,启动页面设成 ip.asp ,然后你通过外网访问时就会显示出你的外访IP。在winform程序里写上如下代码:
public string GetIP()
{
WebClient web = new WebClient();
string hostip = web.DownloadString("http://yourwwww.com.cn/ip.asp");
return hostip;
}
/// 获取用户IP地址
/// </summary>
/// <returns></returns>
public static string GetIPAddress()
{ string user_IP = string.Empty;
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
user_IP = System.Web.HttpContext.Current.Request.UserHostAddress;
}
}
else
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
return user_IP;
}
/// 获取用户IP地址
/// </summary>
/// <returns></returns>
public static string GetIPAddress()
{ string user_IP = string.Empty;
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
user_IP = System.Web.HttpContext.Current.Request.UserHostAddress;
}
}
else
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
return user_IP;
}
if (oIPHost.AddressList.Length > 0)
{
oIPHost.AddressList[]里面找非内网地址
}
用ip访问 会先经过路由再转发回来 就可以知道路由的ip