文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>c# 取外网IP

c# 取外网IP

时间:2010-09-06  来源:小さいです哥

// C# IP地址转长整数
        public long ip2long(String ip)
        {
            System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(ip);
            byte[] bytes = ipaddress.GetAddressBytes();
            Array.Reverse(bytes);
            return BitConverter.ToUInt32(bytes, 0);
        }

        static string GetIP()
        {
            string strUrl = "http://www.ip138.com/ip2city.asp"; //获得IP的网址了
            Uri uri = new Uri(strUrl);
            WebRequest wr = WebRequest.Create(uri);
            Stream s = wr.GetResponse().GetResponseStream();
            StreamReader sr = new StreamReader(s, Encoding.Default);
            string all = sr.ReadToEnd(); //读取网站的数据
            int i = all.IndexOf("[") + 1;
            string tempip = all.Substring(i, 15);
            string ip = tempip.Replace("]", "").Replace(" ", "");
            return ip;
        }

相关阅读 更多 +
排行榜 更多 +
《逃离鸭科夫》一键收集战利品MOD

《逃离鸭科夫》一键收集战利品MOD

行业软件 下载
宝宝巴士宝宝画妈妈猜

宝宝巴士宝宝画妈妈猜

休闲益智 下载
超级模特成长日记最新版

超级模特成长日记最新版

休闲益智 下载