From a04b215547f26ce0d5eb72a78f3a0da93a0c6a45 Mon Sep 17 00:00:00 2001 From: JamieEC <48264520+JamieEC@users.noreply.github.com> Date: Sat, 23 May 2020 00:33:27 +0100 Subject: [PATCH] Add files via upload --- 6to4_converter.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 6to4_converter.py diff --git a/6to4_converter.py b/6to4_converter.py new file mode 100644 index 0000000..a7cacf6 --- /dev/null +++ b/6to4_converter.py @@ -0,0 +1,32 @@ +ipv4Hex = '' +ipv6Hextet1 = '2002' +ipv6Hextet2 = '' +ipv6Hextet3 = '' + +#take input +print('Enter IPv4 address:') +ipv4 = input() + +#split input to octets +ipv4 = ipv4.split('.',4) + +#convert IPv4 address to hex string +for octet in ipv4: + if len(hex(int(octet))[2:])>1: + ipv4Hex += hex(int(octet))[2:] + else: + ipv4Hex += '0' + ipv4Hex += hex(int(octet))[2:] + +#split into hextets +for i in range(4): + ipv6Hextet2 += (ipv4Hex[i]) +for i in range(4,8): + ipv6Hextet3 += (ipv4Hex[i]) + +#Convert to dec and back to remove leading zeros +ipv6Hextet2 = hex(int(ipv6Hextet2,16))[2:] +ipv6Hextet3 = hex(int(ipv6Hextet3,16))[2:] + +#form and print 6to4 address +print(ipv6Hextet1+':'+ipv6Hextet2+':'+ipv6Hextet3+'::/128') \ No newline at end of file