Skip to content

Instantly share code, notes, and snippets.

@kyokuheki
Created March 22, 2018 02:37
Show Gist options
  • Save kyokuheki/cce73254466dc3988bfba55a701891d3 to your computer and use it in GitHub Desktop.
Save kyokuheki/cce73254466dc3988bfba55a701891d3 to your computer and use it in GitHub Desktop.
hex static route for dhcp option 121
import re
# option 121 hex 00c0.a801.0117.c02f.a2c0.a801.0117.c02f.a4c0.a801.0118.c01a.5dc0.a801.0118.c0a8.00c0.a801.0118.ac10.00c0.a801.01
# hex2ip
s = "00c0.a800.0117.c02f.a2c0.a800.0117.c02f.a4c0.a800.0118.c0a8.00c0.a800.0118.ac10.00c0.a800.01"
s = s.replace(".", "")
l = [(i+j) for (i,j) in zip(s[::2],s[1::2])]
l = [(int(x, 16), x) for x in l]
for x,y in l: print("%s\t%s" % (x,y))
# ip2hex
s = "0.192.168.1.1,23.192.47.162.192.168.1.1,23.192.47.164.192.168.1.1,24.192.26.93.192.168.1.1"
l1 = re.split('[.,/]', s)
l2 = [(int(x), hex(int(x))) for x in l1]
for x,y in l1: print("%s\t%s" % (x,y))
# ip2hex
s = "0.192.168.1.1,23.192.47.162.192.168.1.1,23.192.47.164.192.168.1.1,24.192.26.93.192.168.1.1"
l1 = re.split('[.,/]', s)
h1 = ["%02x" % int(x) for x in l1]
h2 = [(i+j) for (i,j) in zip(h1[::2],h1[1::2])]
#h1_it = iter(h1)
#h2 = [i + j for (i, j) in zip(h1_it, h1_it)]
s2 = ".".join(h2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment