比这篇新的文章:
生成四位不重复数字(0-9)的所有组合
比这篇旧的文章: 猜数字游戏的八步以内求解程序
作者: jfxwc, 点击765次, 评论(9), 收藏者(0)
打分:
所有评论,共9条:( 我也来说两句)
比这篇旧的文章: 猜数字游戏的八步以内求解程序
python.普通 IP 转换为十进制 IP
语言: Python, 标签: IP 十进制 2008/06/22发布 6个月前更新作者: jfxwc, 点击765次, 评论(9), 收藏者(0)
Python语言: python.普通 IP 转换为十进制 IP
01 #encoding=utf-8
02 #IP To Decimal
03
04 #This IP is : g.cn
05 IP = '203.208.33.100'
06
07 IP1 = IP.split('.')[0]
08 IP2 = IP.split('.')[1]
09 IP3 = IP.split('.')[2]
10 IP4 = IP.split('.')[3]
11
12 print 'Your IP is : ' + IP
13 print '------------------------------------------------------------'
14 print 'Your Decimal IP is : ' + \
15 str(int(IP1)*256**3 + \
16 int(IP2)*256**2 + \
17 int(IP3)*256 + \
18 int(IP4))
02 #IP To Decimal
03
04 #This IP is : g.cn
05 IP = '203.208.33.100'
06
07 IP1 = IP.split('.')[0]
08 IP2 = IP.split('.')[1]
09 IP3 = IP.split('.')[2]
10 IP4 = IP.split('.')[3]
11
12 print 'Your IP is : ' + IP
13 print '------------------------------------------------------------'
14 print 'Your Decimal IP is : ' + \
15 str(int(IP1)*256**3 + \
16 int(IP2)*256**2 + \
17 int(IP3)*256 + \
18 int(IP4))
所有评论,共9条:( 我也来说两句)
| 1 |
半瓶墨水
6个月前
回复
只调用一次split就行了,不过但就这个程序来说没多大关系
|
| 2 |
呵呵,这个程序是好玩而已,是看见中国建设10进制网络有感而写。
|
| 3 |
@2: split的结果记录下来比如a = IP.split('.'),然后a[0], a[1], a[2], a[3]不就行了。
|
| 4 |
呵呵,多谢半瓶墨水兄指教。现在明白了。
|
| 5 |
|
| 6 |
|
| 7 |
def ip2chr(ip):
|
| 8 |
@7: 呵呵不错的想法
|
| 9 |
还真是一眼看不懂 zsp007 的代码
|
代码