大家都在Startip玩北京有哪些好玩的地方游戏呢?Startip指导的发给我一个

ASP.NET实现根据IP获取省市地址的方法
投稿:shichen2014
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了ASP.NET实现根据IP获取省市地址的方法,主要基于QQwry.dat纯真IP数据库来实现这一功能,非常实用,需要的朋友可以参考下
本文实例讲述了ASP.NET实现根据IP获取省市地址的方法,分享给大家供大家参考。具体实现方法如下:
1、在网站的跟路径下面添加QQWry.dat(点击此处本站下载)文件,这个文件是IP数据库文件
2、添加以下一个类 IPScanner
代码如下:public class IPScanner
&&&&&&& //私有成员#region 私有成员
&&&&&&& private string dataP
&&&&&&& pr
&&&&&&& private long firstStartIp = 0;
&&&&&&& private long lastStartIp = 0;
&&&&&&& private FileStream objfs =
&&&&&&& private long startIp = 0;
&&&&&&& private long endIp = 0;
&&&&&&& private int countryFlag = 0;
&&&&&&& private long endIpOff = 0;
&&&&&&& private string errMsg =
&&&&&&& //构造函数#region 构造函数
&&&&&&& public IPScanner()
&&&&&&&&&&& this.dataPath = System.Web.HttpContext.Current.Server.MapPath("/ipdata/QQWry.dat");
&&&&&&& //公共属性#region 公共属性
&&&&&&& public string DataPath
&&&&&&&&&&& set { dataPath = }
&&&&&&& public string IP
&&&&&&&&&&& set { ip = }
&&&&&&& public string Country
&&&&&&&&&&& get { }
&&&&&&& public string Local
&&&&&&&&&&& get { }
&&&&&&& public string ErrMsg
&&&&&&&&&&& get { return errM }
&&&&&&& //搜索匹配数据#region 搜索匹配数据
&&&&&&& private int QQwry()
&&&&&&&&&&& string pattern = @"(((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))";
&&&&&&&&&&& Regex objRe = new Regex(pattern);
&&&&&&&&&&& Match objMa = objRe.Match(ip);
&&&&&&&&&&& if (!objMa.Success)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& this.errMsg = "IP格式错误";
&&&&&&&&&&&&&&& return 4;
&&&&&&&&&&& }
&&&&&&&&&&& long ip_Int = this.IpToInt(ip);
&&&&&&&&&&& int nRet = 0;
&&&&&&&&&&& if (ip_Int &= IpToInt("127.0.0.0") && ip_Int &= IpToInt("127.255.255.255"))
&&&&&&&&&&& {
&&&&&&&&&&&&&&& this.country = "本机内部环回地址";
&&&&&&&&&&&&&&& this.local = "";
&&&&&&&&&&&&&&& nRet = 1;
&&&&&&&&&&& }
&&&&&&&&&&& else if ((ip_Int &= IpToInt("0.0.0.0") && ip_Int &= IpToInt("2.255.255.255")) || (ip_Int &= IpToInt("64.0.0.0") && ip_Int &= IpToInt("126.255.255.255")) || (ip_Int &= IpToInt("58.0.0.0") && ip_Int &= IpToInt("60.255.255.255")))
&&&&&&&&&&& {
&&&&&&&&&&&&&&& this.country = "网络保留地址";
&&&&&&&&&&&&&&& this.local = "";
&&&&&&&&&&&&&&& nRet = 1;
&&&&&&&&&&& }
&&&&&&&&&&& objfs = new FileStream(this.dataPath, FileMode.Open, FileAccess.Read);
&&&&&&&&&&& try
&&&&&&&&&&& {
&&&&&&&&&&&&&&& objfs.Position = 0;
&&&&&&&&&&&&&&& byte[] buff = new Byte[8];
&&&&&&&&&&&&&&& objfs.Read(buff, 0, 8);
&&&&&&&&&&&&&&& firstStartIp = buff[0] + buff[1] * 256 + buff[2] * 256 * 256 + buff[3] * 256 * 256 * 256;
&&&&&&&&&&&&&&& lastStartIp = buff[4] * 1 + buff[5] * 256 + buff[6] * 256 * 256 + buff[7] * 256 * 256 * 256;
&&&&&&&&&&&&&&& long recordCount = Convert.ToInt64((lastStartIp - firstStartIp) / 7.0);
&&&&&&&&&&&&&&& if (recordCount &= 1)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& country = "FileDataError";
&&&&&&&&&&&&&&&&&&& objfs.Close();
&&&&&&&&&&&&&&&&&&& return 2;
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& long rangE = recordC
&&&&&&&&&&&&&&& long rangB = 0;
&&&&&&&&&&&&&&& long recNO = 0;
&&&&&&&&&&&&&&& while (rangB & rangE - 1)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& recNO = (rangE + rangB) /2;
&&&&&&&&&&&&&&&&&&& this.GetStartIp(recNO);
&&&&&&&&&&&&&&&&&&& if (ip_Int ==this.startIp)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& rangB = recNO;
&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&& }if (ip_Int &this.startIp)
&&&&&&&&&&&&&&&&&&&&&&& rangB = recNO;
&&&&&&&&&&&&&&&&&&& else
&&&&&&&&&&&&&&&&&&&&&&& rangE = recNO;
&&&&&&&&&&&&&&& }this.GetStartIp(rangB);
&&&&&&&&&&&&&&& this.GetEndIp();
&&&&&&&&&&&&&&& if (this.startIp &= ip_Int &&this.endIp &= ip_Int)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& this.GetCountry();
&&&&&&&&&&&&&&&&&&& this.local =this.local.Replace("(我们一定要解放台湾!!!)", "");
&&&&&&&&&&&&&&& }else{
&&&&&&&&&&&&&&&&&&& nRet =3;
&&&&&&&&&&&&&&&&&&& this.country ="未知";
&&&&&&&&&&&&&&&&&&& this.local ="";
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& objfs.Close();
&&&&&&&&&&&&&&& return nR
&&&&&&&&&&& }catch{
&&&&&&&&&&&&&&& return1;
&&&&&&&&&&& }
&&&&&&& }// IP地址转换成Int数据#region IP地址转换成Int数据 privatelong IpToInt(string ip)
&&&&&&&&&&& char[] dot =newchar[] { '.' };
&&&&&&&&&&& string[] ipArr = ip.Split(dot);
&&&&&&&&&&& if (ipArr.Length ==3)
&&&&&&&&&&&&&&& ip = ip +".0";
&&&&&&&&&&& ipArr = ip.Split(dot);
&&&&&&&&&&& long ip_Int =0;
&&&&&&&&&&& long p1 =long.Parse(ipArr[0]) *256*256*256;
&&&&&&&&&&& long p2 =long.Parse(ipArr[1]) *256*256;
&&&&&&&&&&& long p3 =long.Parse(ipArr[2]) *256;
&&&&&&&&&&& long p4 =long.Parse(ipArr[3]);
&&&&&&&&&&& ip_Int = p1 + p2 + p3 + p4;
&&&&&&&&&&& return ip_I
&&&&&&& }//获取起始IP范围#region 获取起始IP范围 privatelong GetStartIp(long recNO)
&&&&&&&&&&& long offSet = firstStartIp + recNO *7;
&&&&&&&&&&& //objfs.Seek(offSet,SeekOrigin.Begin);&&&&&&&&&&&& objfs.Position = offS
&&&&&&&&&&& byte[] buff =new Byte[7];
&&&&&&&&&&& objfs.Read(buff, 0, 7);
&&&&&&&&&&& endIpOff = Convert.ToInt64(buff[4].ToString()) + Convert.ToInt64(buff[5].ToString()) *256+ Convert.ToInt64(buff[6].ToString()) *256*256;
&&&&&&&&&&& startIp = Convert.ToInt64(buff[0].ToString()) + Convert.ToInt64(buff[1].ToString()) *256+ Convert.ToInt64(buff[2].ToString()) *256*256+ Convert.ToInt64(buff[3].ToString()) *256*256*256;
&&&&&&&&&&& return startIp;
&&&&&&& }// 获取结束IP#region 获取结束IP privatelong GetEndIp()
&&&&&&&&&&& //objfs.Seek(endIpOff,SeekOrigin.Begin);&&&&&&&&&&&& objfs.Position = endIpO
&&&&&&&&&&& byte[] buff =new Byte[5];
&&&&&&&&&&& objfs.Read(buff, 0, 5);
&&&&&&&&&&& this.endIp = Convert.ToInt64(buff[0].ToString()) + Convert.ToInt64(buff[1].ToString()) *256+ Convert.ToInt64(buff[2].ToString()) *256*256+ Convert.ToInt64(buff[3].ToString()) *256*256*256;
&&&&&&&&&&& this.countryFlag = buff[4];
&&&&&&&&&&& returnthis.endIp;
&&&&&&& }//获取国家/区域偏移量#region 获取国家/区域偏移量 privatestring GetCountry()
&&&&&&&&&&& switch (this.countryFlag)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& case1:
&&&&&&&&&&&&&&& case2:
&&&&&&&&&&&&&&&&&&& this.country = GetFlagStr(this.endIpOff +4);
&&&&&&&&&&&&&&&&&&& this.local = (1==this.countryFlag) ?"" : this.GetFlagStr(this.endIpOff +8);
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& default:
&&&&&&&&&&&&&&&&&&& this.country =this.GetFlagStr(this.endIpOff +4);
&&&&&&&&&&&&&&&&&&& this.local =this.GetFlagStr(objfs.Position);
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&& }return"";
&&&&&&& }//获取国家/区域字符串#region 获取国家/区域字符串 privatestring GetFlagStr(long offSet)
&&&&&&&&&&& int flag =0;
&&&&&&&&&&& byte[] buff =new Byte[3];
&&&&&&&&&&& while (1==1)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& objfs.Position = offS
&&&&&&&&&&&&&&& flag = objfs.ReadByte();
&&&&&&&&&&&&&&& if (flag ==1|| flag ==2)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& objfs.Read(buff, 0, 3);
&&&&&&&&&&&&&&&&&&& if (flag ==2)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& this.countryFlag =2;
&&&&&&&&&&&&&&&&&&&&&&& this.endIpOff = offSet -4;
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& offSet = Convert.ToInt64(buff[0].ToString()) + Convert.ToInt64(buff[1].ToString()) *256+ Convert.ToInt64(buff[2].ToString()) *256*256;
&&&&&&&&&&&&&&& }else{
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }if (offSet &12)
&&&&&&&&&&&&&&& return"";
&&&&&&&&&&& objfs.Position = offS
&&&&&&&&&&& return GetStr();
&&&&&&& }//GetStr#region GetStr privatestring GetStr()
&&&&&&&&&&& byte lowC =0;
&&&&&&&&&&& byte upC =0;
&&&&&&&&&&& string str ="";
&&&&&&&&&&& byte[] buff =newbyte[2];
&&&&&&&&&&& while (1==1)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& lowC = (Byte)objfs.ReadByte();
&&&&&&&&&&&&&&& if (lowC ==0)
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& if (lowC &127)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& upC = (byte)objfs.ReadByte();
&&&&&&&&&&&&&&&&&&& buff[0] = lowC;
&&&&&&&&&&&&&&&&&&& buff[1] = upC;
&&&&&&&&&&&&&&&&&&& System.Text.Encoding enc = System.Text.Encoding.GetEncoding("GB2312");
&&&&&&&&&&&&&&&&&&& str += enc.GetString(buff);
&&&&&&&&&&&&&&& }else{
&&&&&&&&&&&&&&&&&&& str += (char)lowC;
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& }publicstring IPLocation(string ip)
&&&&&&&&&&& this.ip =
&&&&&&&&&&& this.QQwry();
&&&&&&&&&&& if (this.country.Trim().Contains(this.local.Trim()))
&&&&&&&&&&&&&&& returnthis.country.Trim();
&&&&&&&&&&& returnthis.country.Trim() +this.local.Trim();
3、ASP.NET根据IP获取省市地址的调用
代码如下:string ip="123.81.176.99";
IPScanner ipscaner = new IPScanner();
ipscaner.IPLocation(ip);&
string strIPAddress=ipscaner.C
希望本文所述对大家的C#程序设计有所帮助。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具过年大家一起玩什么? iPad多人互动游戏精品
过年了,大家走亲串门,在一起叙旧玩乐,千万别再拿着不放了。毕竟大家相聚,一起聊天互动才是主要的,拜年、联络感情、叙叙旧、吹吹牛,大家欢聚的时刻一定不能单打独斗。
有时候大家在一起也会玩一些游戏,玩什么呢?在这样一个移动时代,与其看大家都捧着手机,不如一起玩iPad互动游戏,这样在有过节的气氛。
大富翁4 Fun HD
下载地址:点击下载
推荐理由: 大富翁 很多人都玩过,即使没玩过,类似的总玩过,丢色子,撞运气。现在这款游戏移植到了iPad,大家可以在一起重温一下丢色子的乐趣。
藉由掷骰子来决定行进的步数,还可以随意在停留的地方买土地、盖房子,幸运的话还能有财神爷降临。
不过有幸运之神,当然也就有万恶衰神的存在,可千万别被缠上,万一不小心停留在别人的土地上的话,还得掏出双倍的钱来付过路费,可得小心啊!
除了靠运气之外,懂得善加利用卡片道具,也是重要的策略之一喔!
1.熟悉的人物角色,原音呈现的对话,备感亲切!
2.丰富的卡片道具,可以控制步数、强夺土地或现金、盖屋拆屋、迎神送神、陷害对手....让游戏千变万化!
3.神明附身系统,赶快让财神、福神附身保佑你大吉大利,远离虽衰神穷神避免诸事不顺的命运!
4.灵活运用资金投资股市,在地产股市双重获利!
5.内建小游戏: 接金币、射神明、猜兔子,玩游戏赚点数,再以点数购买卡片道具。
主选单中的游乐场中可练习三款小游戏的玩法
6.大型建地可盖公园、加油站、研究中心、渡假饭店等,各有不同的特殊功能
7.自订胜利条件,可用时间、金钱或破产,弹性十足!
8.提供存盘功能,可储存三组不同游戏
下载地址:点击下载
推荐理由:水果忍者是非常好玩、非常易上手的游戏,有一种模式叫对战模式,可以两个人较量一下切水果的水平,多人挑战也可以,为我们的春节增添一些乐趣。
水果忍者是一款简单的休闲游戏,您的目的只有一个,就是砍水果!屏幕上会不断跳出各种水果&&西瓜,凤梨,猕猴桃,草莓,蓝莓,香蕉,苹果等等&&-在它们掉 落之前要快速的全部砍掉!千万别砍到炸弹!不然就over了。iPad 版增加双人对战模式。
玩法介绍:将你的手指扫过屏幕,就能像忍者战士般痛快地切开溅出美味果汁的水果。但注意不要触碰混杂其中的炸弹,一旦引发爆炸,你的刺激冒险便会瞬间终结!
指尖流情Fingle
下载地址:点击下载
推荐理由:过年大家在一起聚会,对于单身那女来说玩这样一款游戏说不定会擦出火花哦。
Fingle是一款iPad双人游戏,确切地说是一款适合宅男、情侣的休闲游戏。为了测试这个游戏,不得不请上我的一位同事以达到更好的体验。MM很好奇,当然也很感兴趣,毕竟大家都喜欢游戏,前面几关还好,可是玩到后面,MM断然拒绝继续玩下去,原因为何?待我为你一一道来。
这个游戏玩法很简单,双方拖动中间带点的实线框到虚线框,并坚持数秒,待到标志着完成进度的透明白色区域满屏就算过关。双方在游戏开始之前,可以各自选择一种颜色:白色和黄色。
初始的关卡比较简单,虚线框是固定不动的,但随着游戏的深入,有些虚线框会动起来,这就更需要男女的配合,手与手的协调。而关卡设计的巧妙之处在于方框的各种排布,加上一些的虚线框,使得玩法多变,十分有趣。之亲是免不了的,你不动,我动;我们一起动;你进,我退,我进,你迎;十指相扣等等,越到后面的关卡,越有挑战,也越有味,再加上让人心跳、至极的背景,也难怪我的那位女性同事HD不住了!
下载地址:点击下载
推荐理由:歌剧之王也是一款可以多人一起互动的游戏,大家一起控制唱歌的胖子,让他走进投影灯下获得更多的分数。
游戏很简单,可以2到4人进行游戏,或者单人和玩,游戏的目的很简单,抢到灯光。游戏不需要玩家控制方向,游戏中的角色会一直转动,玩家只需要在准确的方向按下确定,这是游戏中的歌唱家就会冲过去。
在灯光下歌唱的时间越久,分数也随之越多,在第二轮的抢夺中,最高分的玩家头上会出现皇冠而最低分则出现牛角,牛角貌似能使玩家撞人的时候力气更大小编就喜欢玩最低分撞人,游戏最大的乐趣就是能让朋友一起玩,游戏中歌唱家的语音也很搞笑,总之,这是一款多人游戏的精品,千万别错过哦。
由编辑,转载请注明出处! (
原标题: 电子 过年大家一起玩什么? iPad多人互动游戏精品
编辑: 叶莉 &&
文章地址: /life/digi/14.html
爱美丽编辑推荐:
爱美丽网内容精选
爱美丽专题热点
热点推荐HOT主管给安排我一个网站任务,要求网站日均访问量达100IP(现在每天基本10个左右),希望有人能指导下我该怎么做才能提升? - 搜外问答
大家可以看下这个网站整体情况(www点gold3点hk),对于给出网站重做,或者改版的建议我先谢谢了,这些不是我责任能力范围之内的,我也无权干涉。我主要负责站外推广引流,如今思路有点乱,请求各位前辈指导一下,拜托!!(不得不吐槽一下,这网站做的实在不怎样....)
4,761 次浏览
等 1 人赞同该回答
接触过金融类的站点,的确线上不好推广,我的建议是:
1、找一些个人做的金融沾边的论坛或者流量站点,付费得到一块ad位置,怎么吸引眼球怎么做广告就行了。如果资金充足的话,可以再发展更正规的站点。
2、马上实现seo效果也不现实,建议备案一下,开通百度推广吧,这个流量没问题,不过影响转化的因素太多。注:可能目前百度对金融行业的开户有门槛要求了,证件必须齐全。
3、就像大家说的去发帖,去qq投资理财群去忽悠。别说没用,打个比方,你在seowhy这里求助为什么这么多人帮你回答?你难道不可以化作成一个投资小白去理财论坛装可怜吗?沟通交流的过程中可以适当的加入一些推广的东西,就好像我现在这样,我的qq,在竞价账户方面遇到什么问题,我都可以无偿帮你...
4、现在很多投资人,大部分对移动端的东西很依赖,很多金融类的公众号,都是好资源啊,再有就是,多宣传一下你们的app。
5、金融类的投资类的名博,评论员等,都靠写文章分(吹)析(牛)行(逼)情在找存在感,适当的把软文的质量提高上去,花点钱把“高级水军”渠道给做出来。指望不懂行情没一点名气的屌丝,发点复制小文章,真的不会有太多作用。
没看见有站,只显示玉米出售,你是想卖玉米吗?
每天100IP?
简单,模仿标题党发帖即可。
或者社交平台推广更简单,发到QQ群、QQ空间、博客等也可以。
目的是要卖出域名?
那就是各个域名交易论坛发帖
微博上@各种米农
各种话题炒作这个域名
虽说这是个杂米
谢邀,要想达到目标你可以通过很多方法进行引流,通过你的外推的方法就可以了。
一百个ip还不简单吗?
你主管有其他的业绩要求么?
你每天加些qq群就能做到了
多加各类群,放进去让人家点嘛。。。
直接上流量精灵,挂着机就行
个人感觉还是做付费推广比较有效果。本人接触过一个做白.银.投.资的网站,网站域名有九年了。可能是买过来的,因为和公司名字根本不搭边。网站本身没有多少内容,只是针对一个页面做了优化,外链和内部文章的链接很多都指向这个页面,当这个页面的排名进入到前5业左右的时候,到淘宝上找了一些刷排名的人,将几十个长尾关键词直接刷到首页。然后再做主要关键词的联盟广告推广。因为长尾词数量太多,做联盟不划算,所以就刷排名刷上来。主关键词就那几个,做上来难度很大,所以直接就推广,主做360竞价,还有百度联盟推广。主关键词做百度竞价太贵了!若公司支出能力可以的话就考虑做百度竞价。
接着就是做一些口碑营销,因为这种做投资的,很多人都被坑钱了,然后品牌的负面信息肯定不少,不要以为做口碑和做流量没多大关系。因为负面信息要是在首页,人家一看到这种信息就不会投资,也不会点你们网站去看了,更多的是去找一些相关负面帖子,看看情况是否属实。这部分流量就转移到其他网站,并且通过看了负面贴之后就不会再来,属于“一杆子客户”,就是一杆子被打死的客户,再也不会回来了!
口碑营销怎么做,主要还是靠花钱,现在很多负面贴排在第一页的多数都是一些大网站里面的大板块,版主为了赚些捞偏门的钱,估计把帖子订到首页。这样你想去掉,就要找他删帖。
这种要花钱的地方少不了。毕竟做投资的公司都有钱。一个负面帖子都有可能让你们公司损失价值几百万的客户。
所以该花钱的地方一定要尽快花钱做,别拖了!
个人分析,希望对你有帮助~PS:我没说如何做推广是因为这东西根本做不了什么推广!
30天内高手都在交流什么
微信自媒体实战案例
从零开始玩转微信自媒体
(1 个回答)
(2 个回答)
(2 个回答)
(11 个回答)
(18 个回答)
(36 分钟前)
(53 分钟前)
(56 分钟前)
(56 分钟前)
(58 分钟前)
专注、、运营
给问题设置一定金额,将更容易获得关注与回答。
选择支付方式From Wikipedia, the free encyclopedia
For the Wikipedia user access level, see
An IP address (abbreviation of Internet Protocol address) is an identifier assigned to each computer and other device (e.g., printer, , , etc.) connected to a
that is used to locate and identify the node in communications with other nodes on the network. IP addresses are usually written and displayed in
notations, such as 172.16.254.1 in IPv4, and 2001:db8:0::8:1 in IPv6.
(IPv4) defines an IP address as a
number. However, because of the growth of the Internet and the , a new version of IP (), using 128 bits for the IP address, was developed in 1995, and standardized as
in 1998. Its
commenced in the mid-2000s and is ongoing.
The IP address space is managed globally by the
(IANA), and by five
(RIR) responsible in their designated territories for assignment to end users and , such as . Addresses have been distributed by IANA to the RIRs in blocks of approximately 16.8 million addresses each. Each ISP or private network administrator assigns an IP address to each device connected to its network. Such assignments may be on a static (fixed or permanent) or dynamic basis, depending on its software and practices.
An IP address serves two principal functions: host or network interface
and location . Its role has been characterized as follows: "A
indicates what we seek. An address indicates where it is. A route indicates how to get there."
sent over the
must contain the IP address of both the destination server or
and of the sender (the ). The
(DNS) translates
to the corresponding destination IP address, identifying the computer or device where the services or resources requested by a client are located. Both the source address and the destination address may be changed in transit by a
The sender's IP address is available to the server (which may log it or block it) and becomes the destination address when the server responds to a client request.
can use a device's IP address to deduce its
to determine the country and even the city and post/, organization, or user the IP address has been assigned to, and then to determine a device's actual location. A sender wanting to remain anonymous to the server may use a , which substitutes that server's IP address, as far as the destination server is aware, in place of the true source address. When the destination server responds to the proxy server, it would forward it on to the true client—ie., change the IP address to that of the originator of the request. A
involves the querying of DNS to determine the domain name associated with an IP address.
The sender's IP address is available to the server which can use it in a variety of ways, such as
to control access to a website or network, or to selectively tailor the response to the client's request depending on criteria such as their location, besides other strategies. Whether using a
or a , the IP address that is blocked is the perceived IP address of the client, meaning that if the client is using a
or , blocking one IP address may block other, innocent clients.
Multiple client devices can appear to share an IP address, either because they are part of a
environment or because an IPv4
acts as an
agent on behalf of the client, in which case the real originating IP address might be masked from the server receiving a request. A common practice is to have a NAT mask a large number of devices in a . Only the "outside" interface(s) of the NAT needs to have an Internet-routable address.
Most commonly, the NAT device maps TCP or UDP port numbers on the side of the larger, public network to individual private addresses on the masqueraded network.
In small home networks, NAT functions are usually implemented in a
device, typically one marketed as a "router". In this scenario, the computers connected to the router would have private IP addresses and the router would have a public address to communicate on the Internet. This type of router allows several computers to share one public IP address.
There are two versions of the Internet Protocol (IP): IP version 4 and IP version 6. Each version defines an IP address differently. Because of its prevalence, the generic term IP address typically still refers to the addresses defined by . The gap in version sequence between IPv4 and IPv6 resulted from the assignment of number 5 to the experimental
in 1979, which was never referred to as IPv5.
Main article:
Decomposition of an IPv4 address from
to its binary value.
An IP address in IPv4 is
in size, which limits the
to 4294967296 (232) IP addresses. Of this number, IPv4 reserves some addresses for special purposes such as
(~18 million addresses) or
(~270 million addresses).
IPv4 addresses are usually represented in , consisting of four decimal numbers, each ranging from 0 to 255, separated by dots, e.g., 172.16.254.1. Each part represents a group of 8 bits () of the address. In some cases of technical writing, IPv4 addresses may be presented in various , , or
representations.
In the early stages of development of the Internet Protocol, network administrators interpreted an IP address in two parts: network number portion and host number portion. The highest order octet (most significant eight bits) in an address was designated as the network number and the remaining bits were called the rest field or host identifier and were used for host numbering within a network.
This early method soon proved inadequate as additional networks developed that were independent of the existing networks already designated by a network number. In 1981, the Internet addressing specification was revised with the introduction of
architecture.
allowed for a larger number of individual network assignments and fine-grained
design. The first three bits of the most significant octet of an IP address were defined as the class of the address. Three classes (A, B, and C) were defined for universal
addressing. Depending on the class derived, the network identification was based on octet boundary segments of the entire address. Each class used successively additional octets in the network identifier, thus reducing the possible number of hosts in the higher order classes (B and C). The following table gives an overview of this now obsolete system.
Historical classful network architecture
Size of network
number bit field
Size of rest
of networks
per network
Start address
End address
16,777,216 (224)
127.255.255.255
16,384 (214)
65,536 (216)
191.255.255.255
2,097,152 (221)
223.255.255.255
Classful network design served its purpose in the startup stage of the Internet, but it lacked
in the face of the rapid expansion of the network in the 1990s. The class system of the address space was replaced with
(CIDR) in 1993. CIDR is based on variable-length subnet masking (VLSM) to allow allocation and routing based on arbitrary-length prefixes.
Today, remnants of classful network concepts function only in a limited scope as the default configuration parameters of some network software and hardware components (e.g. netmask), and in the technical jargon used in network administrators' discussions.
Early network design, when global end-to-end connectivity was envisioned for communications with all Internet hosts, intended that IP addresses be uniquely assigned to a particular computer or device. However, it was found that this was not always necessary as
developed and public address space needed to be conserved.
Computers not connected to the Internet, such as factory machines that communicate only with each other via TCP/IP, need not have globally unique IP addresses. Three non-overlapping ranges of IPv4 addresses for private networks were reserved in . These addresses are not routed on the Internet and thus their use need not be coordinated with an IP address registry.
Today, when needed, such private networks typically connect to the Internet through
IANA-reserved private IPv4 network ranges
No. of addresses
24-bit block (/8 prefix, 1 × A)
10.255.255.255
20-bit block (/12 prefix, 16 × B)
172.16.0.0
172.31.255.255
16-bit block (/16 prefix, 256 × C)
192.168.0.0
192.168.255.255
Any user may use any of the reserved blocks. Typically, a network administrator will
for example, many
automatically use a default address range of 192.168.0.0 through 192.168.0.255 (192.168.0.0/24).
Main article:
There has been a higher than originally anticipated demand for IP addresses available for assignment to
and end user organizations since the 1980s, leading to attempts to mitigate the effects of the shortage. IANA's primary
was exhausted on 3 February 2011, when the last five blocks were allocated to the five .
was the first RIR to exhaust its regional pool on 15 April 2011, except for a small amount of address space reserved for the transition to IPv6, intended to be allocated in a restricted process. Individual ISPs still had unassigned pools of IP addresses, and could recycle addresses no longer needed by their subscribers.
Main article:
Decomposition of an IPv6 address from
representation to its binary value.
The rapid exhaustion of IPv4 address space prompted the
(IETF) to explore new technologies to expand the addressing capability in the Internet. The permanent solution was deemed to be a redesign of the Internet Protocol itself. This new generation of the Internet Protocol was eventually named
(IPv6) in 1995. The address size was increased from 32 to 128
(16 ), thus providing up to 2128 (approximately 3.403×1038) addresses. This is deemed sufficient for the foreseeable future.
The intent of the new design was not to provide just a sufficient quantity of addresses, but also redesign routing in the Internet by more efficient aggregation of subnetwork routing prefixes. This resulted in slower growth of routing tables in routers. The smallest possible individual allocation is a subnet for 264 hosts, which is the square of the size of the entire IPv4 Internet. At these levels, actual address utilization rates will be small on any IPv6 network segment. The new design also provides the opportunity to separate the addressing infrastructure of a network segment, i.e. the local administration of the segment's available space, from the addressing prefix used to route traffic to and from external networks. IPv6 has facilities that automatically change the routing prefix of entire networks, should the global connectivity or the routing policy change, without requiring internal redesign or manual renumbering.
The large number of IPv6 addresses allows large blocks to be assigned for specific purposes and, where appropriate, to be aggregated for efficient routing. With a large address space, there is no need to have complex address conservation methods as used in CIDR.
All modern desktop and enterprise server operating systems include native support for the IPv6 protocol, but it is not yet widely deployed in other devices, such as residential networking routers,
(VoIP) and multimedia equipment, and network peripherals.
Just as IPv4 reserves addresses for private networks, blocks of addresses are set aside in IPv6. In IPv6, these are referred to as
reserves the routing prefix fc00::/7 for this block which is divided into two /8 blocks with different implied policies. The addresses include a 40-bit pseudorandom number that minimizes the risk of address collisions if sites merge or packets are misrouted.
Early practices used a different block for this purpose (fec0::), dubbed site-local addresses. However, the definition of what constituted sites remained unclear and the poorly defined addressing policy created ambiguities for routing. This address type was abandoned and must not be used in new systems.
Addresses starting with fe80:, called
addresses, are assigned to interfaces for communication on the attached link. The addresses are automatically generated by the operating system for each network interface. This provides instant and automatic communication between all IPv6 host on a link. This feature is required in the lower layers of IPv6 network administration, such as for the .
Private address prefixes may not be routed on the public Internet.
IP networks may be divided into
and . For this purpose, an IP address is logically recognized as consisting of two parts: the network prefix and the host identifier, or interface identifier (IPv6). The
or the CIDR prefix determines how the IP address is divided into network and host parts.
The term subnet mask is only used within IPv4. Both IP versions however use the CIDR concept and notation. In this, the IP address is followed by a slash and the number (in decimal) of bits used for the network part, also called the routing prefix. For example, an IPv4 address and its subnet mask may be 192.0.2.1 and 255.255.255.0, respectively. The
for the same IP address and subnet is 192.0.2.1/24, because the first 24 bits of the IP address indicate the network and subnet.
IP addresses are assigned to a host by the controlling
or network administrator. IP addresses may be assigned either permanently by a fixed configuration of the hardware or software or it may take place anew at the time of booting. Persistent configuration is also known as a static IP address. In contrast, when a computer's IP address is assigned newly each time a reboot takes place, it is known as a dynamic IP address.
Static IP addresses are manually assigned to a computer or other device by an administrator. The exact procedure varies according to platform. This contrasts with dynamic IP addresses, which are assigned either by the computer interface or host software itself, as in , or assigned by a server using
(DHCP). Even though IP addresses assigned using DHCP may stay the same for long periods of time, they can generally change. In some cases, a network administrator may implement dynamically assigned static IP addresses. In this case, a DHCP server is used, but it is specifically configured to always assign the same IP address to a particular computer. This allows static IP addresses to be configured centrally, without having to specifically configure each computer on the network in a manual procedure.
In the absence or failure of static or stateful (DHCP) address configurations, an operating system may assign an IP address to a network interface using state-less auto-configuration methods, such as Zeroconf.
IP addresses are most frequently assigned dynamically on LANs and broadband networks by DHCP. They are used because it avoids the administrative burden of assigning specific static addresses to each device on a network. It also allows devices to share the limited address space on a network if only some of them will be online at a particular time. In most current desktop operating systems, dynamic IP configuration is enabled by default so that a user does not need to manually enter any settings to connect to a network with a DHCP server. DHCP is not the only technology used to assign IP addresses dynamically. Dialup and some broadband networks use dynamic address features of the .
A sticky dynamic IP address is an informal term used by cable and DSL Internet access subscribers to describe a dynamically assigned IP address which seldom changes. The addresses are usually assigned with DHCP. Since the modems are usually powered on for extended periods of time, the address leases are usually set to long periods and simply renewed. If a modem is turned off and powered up again before the next expiration of the address lease, it will most likely receive the same IP address.
defines an address block, 169.254.0.0/16, for the special use in
for IPv4 networks. In , every interface, whether using static or dynamic address assignments, also receives a local-link address automatically in the block fe80::/10.
These addresses are only valid on the link, such as a local network segment or point-to-point connection, that a host is connected to. These addresses are not routable and like private addresses cannot be the source or destination of packets traversing the Internet.
When the link-local IPv4 address block was reserved, no standards existed for mechanisms of address autoconfiguration. Filling the void,
created an implementation that is called Automatic Private IP Addressing (). APIPA has been deployed on millions of machines and has, thus, become a
in the industry. In , the
defined a formal standard for this functionality, entitled Dynamic Configuration of IPv4 Link-Local Addresses.
Some infrastructure situations have to use static addressing, such as when finding the
(DNS) host that will translate
to IP addresses. Static addresses are also convenient, but not absolutely necessary, to locate servers inside an enterprise. An address obtained from a DNS server comes with a , or , after which it should be looked up to confirm that it has not changed. Even static IP addresses may change as a result of network administration ().
An IP address conflict occurs when two devices on the same local physical or wireless network claim to have the same IP address – that is, they conflict with each other. Since only one of the devices is supposed to be on the network at a time, the second one to arrive will generally stop the IP functionality of one or both of the devices. In many cases with modern , the Operating System will notify the user of one of the devices that there is an IP address conflict (displaying the symptom error message) and then either stop functioning on the network or function very poorly on the network. If one of the devices is the gateway, the network will be crippled. Since IP addresses are assigned by multiple people and systems in multiple ways, any of them can be at fault.
IP addresses are classified into several classes of operational characteristics: unicast, multicast, anycast and broadcast addressing.
The most common concept of an IP address is in
addressing, available in both
and . It normally refers to a single sender or a single receiver, and can be used for both sending and receiving. Usually, a unicast address is associated with a single device or host, but a device or host may have more than one unicast address. Some individual PCs have several distinct unicast addresses, each for its own distinct purpose. Sending the same data to multiple unicast addresses requires the sender to send all the data many times over, once for each recipient.
Main article:
In IPv4 it is possible to send data to all possible destinations ("all-hosts broadcast"), which permits the sender to send the data only once, and all receivers receive a copy of it. In the IPv4 protocol, the address 255.255.255.255 is used for local broadcast. In addition, a directed (limited) broadcast can be made by combining the network prefix with a host suffix composed entirely of binary 1s. For example, the destination address used for a directed broadcast to devices on the 192.0.2.0/24 network is 192.0.2.255. IPv6 does not implement broadcast addressing and replaces it with multicast to the specially-defined all-nodes multicast address.
is associated with a group of interested receivers. In IPv4, addresses 224.0.0.0 through 239.255.255.255 (the former
addresses) are designated as multicast addresses. IPv6 uses the address block with the prefix ff00::/8 for multicast applications. In either case, the sender sends a single datagram from its unicast address to the multicast group address and the intermediary routers take care of making copies and sending them to all receivers that have joined the corresponding multicast group.
Like broadcast and multicast,
is a one-to-many routing topology. However, the data stream is not transmitted to all receivers, just the one which the router decides is logically closest in the network. Anycast address is an inherent feature of only IPv6. In IPv4, anycast addressing implementations typically operate using the shortest-path metric of
and do not take into account congestion or other attributes of the path. Anycast methods are useful for global load balancing and are commonly used in distributed
A public IP address, in common parlance, is a globally routable unicast IP address, meaning that the address is not an address reserved for use in , such as those reserved by , or the various IPv6 address formats of local scope or site-local scope, for example for . Public IP addresses may be used for communication between hosts on the global Internet.
Computer operating systems provide various diagnostic tools to examine their network interface and address configuration.
provides the
and users of
systems can use , , , , , or
utilities to accomplish the task.
: a human-readable alpha-numeric designation that may map to an IP address
, DOD Standard Internet Protocol (January 1980)
, Internet Protocol, Version 6 (IPv6) Specification, S. Deering, R. Hinden (December 1995)
, Internet Protocol, Version 6 (IPv6) Specification, S. Deering, R. Hinden, The Internet Society (December 1998)
, Internet Protocol – DARPA Internet Program Protocol Specification (September 1981)
Comer, Douglas (2000).
Upper Saddle River, NJ: Prentice Hall. p. 394.  .
Smith, L Lipner, Ian (3 February 2011). .
ICANN,nanog mailing list. .
Asia-Pacific Network Information Centre (15 April 2011).
section 3.2.1
. . 7 January . "Updated: January 7, 2009"
. . 7 January . "Updated: 7 January 2009"
Mitchell, Bradley. .
Kishore, Aseem (4 August 2009). . Online Tech Tips Online- 2013.
. . 22 November .
2013. Article ID: 133490 – Last Review: 15 October 2013 – Revision: 5.0
Moran, Joseph (1 September 2010). .
: Hidden categories:

我要回帖

更多关于 北京有哪些好玩的地方 的文章

 

随机推荐