La Vita è Bella
Tuesday, April 28, 2009
A script for Columbus V-900 GPS
Columbus V-900 is so far the GPS that best fit my requirements: it can log, it can take waypoints while logging, and it (can) have a big storage for logging (via TF card). I got one from WC, a friend to give it a try.
It log GPS tracks to CSV format, WC wrote a script to convert it to the GPX format, but without waypoints. So I rewrote a Python script (as I'm not so familiar with perl), to add the waypoints to the GPX file.
Get the script here, it will use the voice record filename as the name of the waypoint if available, or otherwise just "Waypoint #N". You may want to edit the converted GPX file to rename the waypoints.
tags: script, python, gps, columbus, v900, gpx
11:47:57 by fishy - dev - Permanent Link
no comments yet - 1 trackback - karma: 51 [+/-]
Thursday, April 02, 2009
Python script to convert from IP range to IP mask
This script will convert a line contains start and end IP separated by space like:
221.192.0.0 221.199.207.255
Into IP mask format (with comment) like:
#221.192.0.0 - 221.199.207.255
221.192.0.0/14
221.196.0.0/15
221.198.0.0/16
221.199.0.0/17
221.199.128.0/18
221.199.192.0/20
The script is:
1 #!/usr/bin/env python
2
3 import sys
4 import re
5
6 def ip2int(ip) :
7 ret = 0
8 match = re.match("(\d*)\.(\d*)\.(\d*)\.(\d*)", ip)
9 if not match : return 0
10 for i in xrange(4) : ret = (ret << 8) + int(match.groups()[i])
11 return ret
12
13 def int2ip(ipnum) :
14 ip1 = ipnum >> 24
15 ip2 = ipnum >> 16 & 0xFF
16 ip3 = ipnum >> 8 & 0xFF
17 ip4 = ipnum & 0xFF
18 return "%d.%d.%d.%d" % (ip1, ip2, ip3, ip4)
19
20 def printrange(startip, endip) :
21 bits = 1
22 mask = 1
23 while bits < 32 :
24 newip = startip | mask
25 if (newip>endip) or (((startip>>bits) << bits) != startip) :
26 bits = bits - 1
27 mask = mask >> 1
28 break
29 bits = bits + 1
30 mask = (mask<<1) + 1
31 newip = startip | mask
32 bits = 32 - bits
33 print "%s/%d" % (int2ip(startip), bits)
34 if newip < endip :
35 printrange(newip + 1, endip)
36
37 while 1 :
38 line = sys.stdin.readline().strip()
39 if not line : break
40 chars = line.split(" ")
41 print "#%s - %s" % (chars[0], chars[1])
42 ip1 = ip2int(chars[0])
43 ip2 = ip2int(chars[1])
44 printrange(ip1, ip2)
45
tags: code, python, ip, range, mask
18:57:10 by fishy - dev - Permanent Link
no comments yet - no trackbacks yet - karma: 14 [+/-]


