1
0
Fork 0

„ipcalc.py“ hinzufügen

master
mosers vor 5 Jahren
Ursprung 749b8148df
Commit 681af9383e

@ -0,0 +1,27 @@
#!/usr/bin/python3
from sys import argv
from re import search
try:
ip = argv[1]
except Exception as e:
print("Usage: ipcalc.py <IP ADDRESS>")
exit(0)
if not search("^(\d{1,3}\.){3}\d{1,3}$", ip):
print(f"Invalid address {ip}")
exit(0)
ipdec = list(map(int, ip.split(".")))
ipdec[0] = ipdec[0]*256**3
ipdec[1] = ipdec[1]*256**2
ipdec[2] = ipdec[2]*256**1
ipdec[3] = ipdec[3]*256**0
sum0 = sum(ipdec)
p1 = int(ipdec.pop(0)/256**3)
sum1 = sum(ipdec)
p2 = int(ipdec.pop(0)/256**2)
sum2 = sum(ipdec)
w = len(ip)+8
print(f'Address {ip} equals dec {sum0} / {p1}.{sum1} / {p1}.{p2}.{sum2}')
print(f'{" ": <{w}} equals oct 0{sum0:o} / 0{p1:o}.0{sum1:o} / 0{p1:o}.0{p2:0}.0{sum2:o}')
print(f'{" ": <{w}} equals hex {sum0:#x} / {p1:#x}.{sum1:#x} / {p1:#x}.{p2:#x}.{sum2:#x}')
Laden…
Abbrechen
Speichern