Fix lint errors in CI #2
This commit is contained in:
44
app/main.py
44
app/main.py
@@ -6,41 +6,45 @@ import argparse
|
|||||||
|
|
||||||
|
|
||||||
def parse_args(): # pragma: no cover
|
def parse_args(): # pragma: no cover
|
||||||
parser = argparse.ArgumentParser(description='Get 6to4 address from IPv4 address.')
|
parser = argparse.ArgumentParser(description="Get 6to4 address from IPv4 address.")
|
||||||
parser.add_argument('-a', '--address', dest='address', action='store', help='IPv4 address', required=True)
|
parser.add_argument(
|
||||||
args = parser.parse_args()
|
"-a",
|
||||||
return args
|
"--address",
|
||||||
|
dest="address",
|
||||||
|
action="store",
|
||||||
|
help="IPv4 address",
|
||||||
|
required=True,
|
||||||
|
)
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def ipv4_to_ipv6(ipv4):
|
def ipv4_to_ipv6(ipv4):
|
||||||
ipv4Hex = ''
|
ipv4_hex = ""
|
||||||
ipv6Hextet1 = '2002'
|
ipv6_hextets = ["", ""]
|
||||||
ipv6Hextet2 = ''
|
|
||||||
ipv6Hextet3 = ''
|
|
||||||
|
|
||||||
# Split input to octets
|
# Split input to octets
|
||||||
ipv4 = ipv4.split('.',4)
|
ipv4 = ipv4.split(".", 4)
|
||||||
|
|
||||||
# Convert IPv4 address to hex string
|
# Convert IPv4 address to hex string
|
||||||
for octet in ipv4:
|
for octet in ipv4:
|
||||||
if len(hex(int(octet))[2:])>1:
|
if len(hex(int(octet))[2:]) > 1:
|
||||||
ipv4Hex += hex(int(octet))[2:]
|
ipv4_hex += hex(int(octet))[2:]
|
||||||
else:
|
else:
|
||||||
ipv4Hex += '0'
|
ipv4_hex += "0"
|
||||||
ipv4Hex += hex(int(octet))[2:]
|
ipv4_hex += hex(int(octet))[2:]
|
||||||
|
|
||||||
# Split into hextets
|
# Split into hextets
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
ipv6Hextet2 += (ipv4Hex[i])
|
ipv6_hextets[0] += ipv4_hex[i]
|
||||||
for i in range(4,8):
|
for i in range(4, 8):
|
||||||
ipv6Hextet3 += (ipv4Hex[i])
|
ipv6_hextets[1] += ipv4_hex[i]
|
||||||
|
|
||||||
# Convert to dec and back to remove leading zeros
|
# Convert to dec and back to remove leading zeros
|
||||||
ipv6Hextet2 = hex(int(ipv6Hextet2,16))[2:]
|
ipv6_hextets[0] = hex(int(ipv6_hextets[0], 16))[2:]
|
||||||
ipv6Hextet3 = hex(int(ipv6Hextet3,16))[2:]
|
ipv6_hextets[1] = hex(int(ipv6_hextets[1], 16))[2:]
|
||||||
|
|
||||||
# Form 6to4 address
|
# Form 6to4 address
|
||||||
output_6to4 = f"{ipv6Hextet1}:{ipv6Hextet2}:{ipv6Hextet3}::/128"
|
output_6to4 = f"2002:{ipv6_hextets[0]}:{ipv6_hextets[1]}::/128"
|
||||||
return output_6to4
|
return output_6to4
|
||||||
|
|
||||||
|
|
||||||
@@ -50,5 +54,5 @@ def main(): # pragma: no cover
|
|||||||
print(output)
|
print(output)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main() # pragma: no cover
|
main() # pragma: no cover
|
||||||
|
|||||||
Reference in New Issue
Block a user