如何捕获用户的IP地址并存储在数据库中... [英] How Catch the User's IP Address and to store in Database...

查看:245
本文介绍了如何捕获用户的IP地址并存储在数据库中...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我们正在开发一个用户填写表单的应用程序。我需要抓住该系统的IP地址......任何人都可以帮助我

解决方案

下面是获取公共IP的代码



  public   string  GetPublicIP( )
{
String direction = ;
WebRequest request = WebRequest.Create( http://checkip.dyndns.org/);
使用(WebResponse response = request.GetResponse())
使用(StreamReader) stream = new StreamReader(response.GetResponseStream()))
{
direction = stream.ReadToEnd();
}

// 在html中搜索ip
int first = direction.IndexOf( 地址:)+ 9 ;
int last = direction.LastIndexOf( < /体>中);
direction = direction.Substring(first,last - first);

返回方向;
}





http://stackoverflow.com/questions/1069103/how-to-get-my-own-ip-address-in-c [<一个href =http://stackoverflow.com/questions/1069103/how-to-get-my-own-ip-address-in-ctarget =_ blanktitle =新窗口> ^ ]


Hi we are developing an Application from which user fills the Form . And i need to Catch the IP Address of that system ... can any one help me

解决方案

Below is the code to get Public IP

public string GetPublicIP()
{
    String direction = "";
    WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
    using (WebResponse response = request.GetResponse())
    using (StreamReader stream = new StreamReader(response.GetResponseStream()))
    {
        direction = stream.ReadToEnd();
    }

    //Search for the ip in the html
    int first = direction.IndexOf("Address: ") + 9;
    int last = direction.LastIndexOf("</body>");
    direction = direction.Substring(first, last - first);

    return direction;
}



http://stackoverflow.com/questions/1069103/how-to-get-my-own-ip-address-in-c[^]


这篇关于如何捕获用户的IP地址并存储在数据库中...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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