twister-core/contrib/seeds/makeseeds.py

39 lines
901 B
Python
Raw Normal View History

2013-01-30 03:17:56 +00:00
#!/usr/bin/env python
#
# Generate pnSeed[] from Pieter's DNS seeder
#
NSEEDS=600
import re
import sys
from subprocess import check_output
def main():
lines = sys.stdin.readlines()
ips = []
2015-08-01 21:44:00 +00:00
ports = []
pattern = re.compile(r"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}):(\d{1,5})")
2013-01-30 03:17:56 +00:00
for line in lines:
m = pattern.match(line)
if m is None:
continue
ip = 0
for i in range(0,4):
ip = ip + (int(m.group(i+1)) << (8*(i)))
if ip == 0:
continue
ips.append(ip)
2015-08-01 21:44:00 +00:00
ports.append(int(m.group(5)))
2013-01-30 03:17:56 +00:00
for row in range(0, min(NSEEDS,len(ips)), 8):
print " " + ", ".join([ "0x%08x"%i for i in ips[row:row+8] ]) + ","
2015-08-01 21:44:00 +00:00
for row in range(0, min(NSEEDS,len(ports)), 8):
print " " + ", ".join([ "0x%04x"%i for i in ports[row:row+8] ]) + ","
2013-01-30 03:17:56 +00:00
if __name__ == '__main__':
main()