Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python script for finding a still available pretty phonenumber on the sha2017 POC network.
Register your phone number on:
Author: Willem Hengeveld <>
This code is released under the Beerware license.
from __future__ import print_function
from urllib2 import urlopen
except ImportError:
from urllib.request import urlopen
import xml.etree.ElementTree as etree
def download_phonebook():
""" download the phonebook in xml format """
response = urlopen('')
def parse_phonebook(xmldata):
""" convert the xml data to a dictionary of { extension => name } """
pb = dict()
tree = etree.fromstring(xmldata)
for ent in tree.find('entries'):
ext = ent.find('extension')
name = ent.find('name')
pb[ext.text] = name.text
return pb
def genpretty2(i, j):
""" yield all 'pretty' numbers with 2 distinct digits """
yield "%d%d%d%d" % (i,j,j,j)
yield "%d%d%d%d" % (j,i,j,j)
yield "%d%d%d%d" % (j,j,i,j)
yield "%d%d%d%d" % (j,j,j,i)
yield "%d%d%d%d" % (i,j,i,j)
yield "%d%d%d%d" % (i,i,j,j)
yield "%d%d%d%d" % (i,j,j,i)
def genpretty1(i):
""" yield all 'pretty' numbers with 1 digit """
yield "%d%d%d%d" % (i,i,i,i)
yield "%d%d%d%d" % (i,(i+1)%10,(i+2)%10,(i+3)%10)
yield "%d%d%d%d" % (i,(i-1)%10,(i-2)%10,(i-3)%10)
def genpretty(i, j):
if i==j:
for nr in genpretty1(i):
yield nr
for nr in genpretty2(i, j):
yield nr
def findpretty(pb):
""" return a set of pretty numbers which are not yet in the phonebook """
found = set()
for i in range(10):
for j in range(10):
for nr in genpretty(i,j):
if nr >= "2000" and nr <= "9999" and not nr in pb:
return found
def main():
pb = parse_phonebook(download_phonebook())
found = findpretty(pb)
print("pretty phonenumbers still available on the SHA2017 POC network")
print(" ".join(found))
if __name__ == '__main__':

This comment has been minimized.

Copy link
Owner Author

@nlitsme nlitsme commented Jul 30, 2017

Running code is available here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment