github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

fishy / scripts

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (2)
  • Wiki (2)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

various scripts wrote by me — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

 * v0.3 of projtags, can add commands now 
Yuxuan 'fishy' Wang (author)
Fri Jul 31 02:36:48 -0700 2009
commit  2b86184edfad6baae7a0eb259aae8eaaa15d9482
tree    8fde714383daead4d44c83b7b0e24f20e327aa4b
parent  08bd4d75fa8e086dc53af0a3cadcce2605706d7f
scripts / convertip.py convertip.py
100755 46 lines (39 sloc) 0.971 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
 
import sys
import re
 
def ip2int(ip) :
ret = 0
match = re.match("(\d*)\.(\d*)\.(\d*)\.(\d*)", ip)
if not match : return 0
for i in xrange(4) : ret = (ret << 8) + int(match.groups()[i])
return ret
 
def int2ip(ipnum) :
ip1 = ipnum >> 24
ip2 = ipnum >> 16 & 0xFF
ip3 = ipnum >> 8 & 0xFF
ip4 = ipnum & 0xFF
return "%d.%d.%d.%d" % (ip1, ip2, ip3, ip4)
 
def printrange(startip, endip) :
bits = 1
mask = 1
while bits < 32 :
newip = startip | mask
if (newip>endip) or (((startip>>bits) << bits) != startip) :
bits = bits - 1
mask = mask >> 1
break
bits = bits + 1
mask = (mask<<1) + 1
newip = startip | mask
bits = 32 - bits
print "%s/%d" % (int2ip(startip), bits)
if newip < endip :
printrange(newip + 1, endip)
 
while 1 :
line = sys.stdin.readline().strip()
if not line : break
chars = line.split(" ")
print "#%s - %s" % (chars[0], chars[1])
ip1 = ip2int(chars[0])
ip2 = ip2int(chars[1])
printrange(ip1, ip2)
 
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server