Skip to content

Instantly share code, notes, and snippets.

@gwire
Created February 8, 2017 14:33
Show Gist options
  • Save gwire/0952739eb9a872ec2df9185a0de738dc to your computer and use it in GitHub Desktop.
Save gwire/0952739eb9a872ec2df9185a0de738dc to your computer and use it in GitHub Desktop.
takes an SSHFP record and converts to tinydns format
#!/usr/bin/env python
# tinysshfp - takes the output of "ssh-keygen -r" and converts into tinydns
#
# example: ssh-keygen -r example.com | ./tinysshfp.py
#
# 2017 Lee Maguire
import getopt
import sys
import re
ttl = ""
def tinySshfpRecord( hostname, algid, fptype, fp, ttl ):
fpout = ""
for c in range(0, len(fp), 2):
fpout = fpout + "\\{0:03o}".format(int("0x"+fp[c]+fp[c+1],16))
return(":" + hostname + ":44:" + "\\{0:03o}".format(int(algid)) + "\\{0:03o}".format(int(fptype)) + fpout + ":" + ttl);
opts, args = getopt.getopt(sys.argv[1:],"ht:",["ttl="])
for opt, arg in opts:
if opt == '-h':
print 'Usage: tinysshfp.py -t 60'
sys.exit()
elif opt in ("-t", "--ttl"):
ttl = arg
for input_text in sys.stdin:
hostname,xin,xsshfp,algid,fptype,fp = input_text.rstrip().split(" ")
line = tinySshfpRecord( hostname, algid, fptype, fp, ttl )
sys.stdout.write( line + "\n")
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment