1. åå¨ä¸ä¸ªIPv4å°åä½ä¸ºbinaryï¼4ï¼æ¯æçå®çï¼ä»¥ç©¶ç«æå³çä»ä¹ï¼å¹¶ä¸å¯ä»¥å¾å®¹æé¢ç½©å¼çæ¥è¯¢ãä½æ¯ï¼å®éè¦è½¬æ¢åéåºï¼å¦æä½ çææ¬å表示ï¼å®é
ä¸ãå¨è¿ç§æ
åµä¸ï¼æ¨å¯è½æ´å欢ä¸ä¸ªåç¬¦ä¸²æ ¼å¼ã ä¸ä¸ªSQL Serverçå½æ° CodeGo.netï¼å¯ä»¥å¸®å©å¦æä½ æ¯åå¨ä¸ºä¸ä¸ªå符串æ¯PARSENAME顺便æä¸ä¸ãä¸æ¯ä¸ä¸ºIPå°åï¼ä½å®å
¨éåä»ä»¬ãä¸é¢çè°ç¨å°è¿å'14'ï¼SELECT PARSENAME('123.234.23.14', 1)
ï¼ç¼å·ä¸ºä»å³å°å·¦ï¼ã
2. æé常为varcharï¼15ï¼ï¼ç¨äºIPv4å°å-ä½å®ä»¬æåºæ¯ä¸ç§çè¦ï¼é¤éä½ å«é¶ã æè¿ä¿åå®ä»¬ä½ä¸ºè¿å»çè¯ éãSystem.Net.IPAddressæGetAddressBytesæ¹æ³ï¼è¯¥æ¹æ³å°è¿åçIPå°å为4åè表示çIPå°åçæ°ç»ãä½ ä¸é¢çCï¼ä»£ç ç转æ¢IPAddresså°int...var ipAsInt = BitConverter.ToInt32(ip.GetAddressBytes(), 0);
æï¼æä¸å¾ä¸åäºå¾å¤å¯»æ¾éå¤æ°æ®å é¤çå°åï¼å¹¶å¸æ该ææ æ¯å°ï¼è¶å¿«è¶å¥½ãç¶åæå°åèåºçintåæIPAddressNETä¸ç对象ï¼è¯·ä½¿ç¨GetByteså¨æ¹æ³BitConverterå¾å°intä½ä¸ºä¸ä¸ªåèæ°ç»ãéè¿è¯¥åèæ°ç»çæé å½æ°IPAddressè¿éè¦ä¸ä¸ªåèæ°ç»ï¼ä½ æç»å¤ä»½ä¸IPAddressæ¨å¼å§ä½¿ç¨ãvar myIp = new IPAddress(BitConverter.GetBytes(ipAsInt));
3. 对äºè¿ä¸ªå¨æ¥åççæ¡ å®ä»¬æåºæ¯ä¸ç§çè¦ï¼é¤éä½ å« é¶ã ä¸é¢æ¯SQL Server 2008çä¸ä¸ªææï¼ä»ä¼è¨å
å¥çå¨è¿æ¬ä¹¦ï¼with ip_addresses as
(
SELECT '131.33.2.201' AS ip_address UNION ALL
SELECT '2.12.4.4' AS ip_address UNION ALL
SELECT '131.33.2.202' AS ip_address UNION ALL
SELECT '2.12.4.169' AS ip_address UNION ALL
SELECT '131.107.2.201' AS ip_address
)
select ip_address
from ip_addresses
ORDER BY CAST('/' + ip_address + '/' AS hierarchyid)
åæ¥ip_address
-------------
2.12.4.4
2.12.4.169
131.33.2.201
131.33.2.202
131.107.2.201
4. ææå欢çæç« è°å°ä¸ºä»ä¹ä½ ä¸è¯¥'æ£å表达å¼æ¥è§£æIPå°åã大å¤æ°ä»ä»¬æ£å¨è°è®ºçæ¯çæ£è§£é为ä»ä¹ä½ åºè¯¥é常å°å¿çIPå°åçææ¬è¡¨ç¤ºãæå»ºè®®ä½ å³å®ä»ä¹æ°æ®ç±»åå¨æ°æ®åºä¸ä¹å读å®ï¼å¤§æ¦ä¹å 为ç§ç§å¤çæ¨çåºç¨ç¨åºä¼åï¼å³ä½¿æç« æ¯åå
³äºPerlï¼å®çä»»ä½è¯è¨ï¼ã ææ³å¨å¹´åºç32ä½æ°æ®ç±»åï¼æ4个8ä½æ°æ®ç±»åï¼å°æ¯æ好çéæ©ã
5. æå¨è¿é读äºå¾å¤ç±»ä¼¼çé®é¢ï¼å¹¶æ²¡æå¨è¿ä¸ªå¨å«äººç头å·çæ¡ççå¤ï¼â对äºIPv4å°åï¼æ¨å¯è½å¸æå°å®ä»¬ä¿å为ä¸ä¸ªæ 符å·æ´åçINET_ATONï¼ï¼åINET_NTOAï¼ï¼å½æ°è¿åå
¶å¼çIPå°åï¼åä¹äº¦ç¶âãææ³è¿å°±æ¯æè¦å¨æçåè´èµ°ï¼é¤éæå¨ä¸é¢å³å®ã
6. æ好çæ¹æ³ï¼å½ä¸éè¦æåºå对IPçå
¶ä»æ§å¶ï¼æ¯å
¶åå¨ä¸ºæ´æ°ï¼å°å
¶åå¨ä¸ºvarcharçå°è±è´¹ä¸ä»
ä»
æ¯ä¸ä¸ªç®åçæ è¾æ´åçæ¹å¼æ´å¤çæ§è½ã æä¸ä¸ªå±æ§IPAddress.Addressä½å®æ¯è¿æ¶çï¼æä¹ä¸ç¥é为ä»ä¹ï¼å 为å¦æä½ ä¸éè¦æåºæéè¿IPç±»æ§å¶ï¼æ好çåæ³æ¯å°å
¶åå¨ä¸ºæ 符å·æ´æ°ï¼å³æä¸ä¸ªæ大å¼0xffffffffå®çäº255.255.255.255å¨åè¿å¶è¡¨ç¤ºã ä¹IPAddressç±»æä¸ä¸ªæ¥åé¿æçæé å¹¶æ ¹æ®VSè°è¯å¨å¯è§åå·¥å
·ï¼å³IPAddressç±»æ¬èº«åå¨å®çå
é¨åéä½ä¸ºä¸ä¸ªæ°åï¼èä¸æ¯åèæ°ç»ï¼ã äºè§£æ´å¤å
³äºåå¨ç解å³æ¹æ³å¨MS SQL Serverçåä½ï¼ å¨MS SQL 4åèæ 符å·æ´åï¼ SQL Serverç4åèæ 符å·æ´å
7. IPV4ï¼ INTï¼æTINYINTÃ4ï¼ è¿ççåå³äºå®æ¯å¦åªæ¯åå¨åæ£ç´¢æå¦æå®çå°æ¯ä¸ä¸ªè¿ç¨çæç´¢æ¡ä»¶ã
8. ä¸è¦å¿äºIPv6ç-ä½ éè¦æ´å¤çæ¿é´ï¼å¦æä½ éè¦åå¨å®ä»¬-128为IPv4ç32ã æä¼å»çbigintï¼ä½ä½ éè¦å¸®æç代ç ç¿»è¯å°äººç±»å好ççæ¬ã
9. 对äºç©ºé´é«æçåå¨åå½å¼æ¯è¦è¢«å¤çï¼å¹é
çèå´ï¼ï¼ä¸ä¸ªintã IPå°åççåªæ¯ä¸ä¸ª32ä½çå¼ã 对äºä¸ä¸ªç®åç解å³æ¹æ¡ï¼ä½ åªæ¯è¦åå¨çå¼æ¥æ¥çå®ï¼ä¸varchar(15)åå¨IPå°åçå符串表示表åã
10. æå¯è½ä¼ç¨ä¸ä¸ªå»varcharæcharã å大å°è®¾ç½®ä¸º15ã
11. PHPï¼ç¶åPHP5æ2个å
ç½®ç转æ¢å½æ°ï¼ ip2longålong2ipï¼æï¼å®è¿å/转æ¢æ符å·æ´æ°
12. æå·²ç»åå¤äºè¿è¡åSMALLINTï¼æå
¶ä»çå°çæ´æ°æ°æ®ç±»åï¼ä½ å欢ï¼å-æ¯ä¸ªå
«ä½ä½ç»ãç¶åï¼ä½ å¯ä»¥åä¸ä¸ªè§å¾ï¼å®æç ´å¨ä¸èµ·ä½ä¸ºä¸ä¸ªcharå符串ï¼æ¾ç¤ºï¼æåä½ å¯ä»¥åç®åçè¿ç®ç¬¦æ¥å³å®è°é½æ¯å¨çä»ä¹ è¿æ¯ç¸å½å¿«çï¼åªè¦ä½ åæ£ç¡®çç´¢å¼ï¼ï¼å¹¶ä¸è¿å
许å¾å®¹ææ¥è¯¢ï¼æ²¡æå符串æä½ï¼ï¼ã
13. ç±äºIPå°åæ32ä½ï¼å®å¯ä»¥ä½ å¾é¿çä¿åä»·å¼ï¼ å®ä¸ä¼æ¯å 为空é´æµªè´¹VARCHARï¼ä½éåä½ ä¼æ¶å°å°å
¶è§£ç åä¸ä¸ªIPï¼æ¯ä¸ä¸ªåæ¶å»¶åå¼éææ¬å¯è½ä¸å¼å¾ã
14. å¼ç¨è¿æ ·çï¼ å¨CHARåå¨IPå°åï¼15ï¼æ±ãè¿åå³äºæå¤å°æ°æ®è¦åå¨ï¼è¿å¯è½æ¯é常浪费çï¼ä¸ºä»ä¹æ们éè¦åå¨çç¹ï¼ï¼
温馨提示:答案为网友推荐,仅供参考