首页 > 其他 > 详细

根据IP标识用户

时间:2017-01-19 11:10:34      阅读:348      评论:0      收藏:0      [点我收藏+]

一、C#版

 1 //获取内网IP
 2 private string GetInternalIP()
 3 {
 4     IPHostEntry host;
 5     string localIP = "?";
 6     host = Dns.GetHostEntry(Dns.GetHostName());
 7     foreach (IPAddress ip in host.AddressList)
 8     {
 9         if (ip.AddressFamily.ToString() == "InterNetwork")
10         {
11             localIP = ip.ToString();
12             break;
13         }
14     }
15     return localIP;
16 }
 1 //获取外网IP
 2 private string GetExternalIP()
 3 {
 4     string direction = "";
 5     WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
 6     using (WebResponse response = request.GetResponse())
 7     using (StreamReader stream = new StreamReader(response.GetResponseStream()))
 8     {
 9         direction = stream.ReadToEnd();
10     }
11     int first = direction.IndexOf("Address:") + 9;
12     int last = direction.LastIndexOf("</body>");
13     direction = direction.Substring(first, last - first);
14     return direction;
15 }

 

根据IP标识用户

原文:http://www.cnblogs.com/BurtBlog/p/6305755.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!