From 8e7667cd805456520e32d0862f8f12050149a2a3 Mon Sep 17 00:00:00 2001 From: lickthecheese Date: Sun, 27 Sep 2020 15:57:01 -0400 Subject: [PATCH] steal jess's hex scripts --- .vimrc | 2 +- bin/hexch | 15 +++++++++++++++ bin/unhexch | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 bin/hexch create mode 100755 bin/unhexch diff --git a/.vimrc b/.vimrc index 7a51360..e1a877c 100644 --- a/.vimrc +++ b/.vimrc @@ -11,7 +11,7 @@ command Tmd :r ~/Documents/templates/md.html " run groff+refer on file :command Groff !sh -c 'p="%"; refer -PS -e -p ~/Documents/bib ${p::-4}.mom | groff -mom -Tpdf > ${p::-4}.pdf' -:command Grofft !sh -c 'p="%"; refer -PS -e -p ~/Documents/bib ${p::-4}.mom | groff -mom -T ascii > ${p::-4}.txt' +:command Grofft !sh -c 'p="%"; refer -PS -e -p ~/Documents/bib ${p::-4}.mom | groff -mom -T ascii | sed -b "s/\x1b[^m]*m//g" > ${p::-4}.txt' :command Man !sh -c 'p="%"; groff -man -T ascii ${p::-4}.man > ${p::-4}.txt' :command Md !p="%"; cmark --unsafe ${p::-3}.md | h2p - ${p::-3}.pdf diff --git a/bin/hexch b/bin/hexch new file mode 100755 index 0000000..fd87caa --- /dev/null +++ b/bin/hexch @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + +import argparse + +def _hexip(ip: str): + parts = [int(p) for p in ip.split(".")] + return ''.join("{:02x}".format(p) for p in parts) + +if __name__ == "__main__": + parser = argparse.ArgumentParser("webchat IP hexlify") + parser.add_argument("ip") + args = parser.parse_args() + + print(_hexip(args.ip)) + diff --git a/bin/unhexch b/bin/unhexch new file mode 100755 index 0000000..8590e7b --- /dev/null +++ b/bin/unhexch @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import argparse + +def _hexip(s: str): + ip = [] + for i in range(0, len(args.hex), 2): + octet = int(args.hex[i:i+2], 16) + ip.append(str(octet)) + return ".".join(ip) + +if __name__ == "__main__": + parser = argparse.ArgumentParser("webchat IP dehexlify") + parser.add_argument("hex") + args = parser.parse_args() + + print(_hexip(args.hex)) +