Refactored ulagen.py to Python 3

This commit is contained in:
Sun Knudsen 2020-12-10 07:24:56 -05:00
parent 8858839a7b
commit 69302fcd9f
No known key found for this signature in database
GPG Key ID: 1FA767862BBD1305
3 changed files with 8 additions and 8 deletions

View File

@ -231,7 +231,7 @@ $ source ~/.bashrc
#### Install cURL and Python
```shell
apt install -y curl python
apt install -y curl python3
```
#### Generate random IPv6 ULA and save to environment variables
@ -241,8 +241,8 @@ Shout out to [Andrew Ho](https://gist.github.com/andrewlkho/31341da4f5953b8d977a
The following command downloads and runs [ulagen.py](./ulagen.py) ([PGP signature](./ulagen.py.sig), [PGP public key](https://sunknudsen.com/sunknudsen.asc)).
```console
$ curl -s https://sunknudsen.com/static/media/privacy-guides/how-to-self-host-hardened-strongswan-ikev2-ipsec-vpn-server-for-ios-and-macos/ulagen.py | python | grep "First subnet" | awk '{print "STRONGSWAN_IPV6_ULA="$3}' | tee -a ~/.bashrc
STRONGSWAN_IPV6_ULA=fdcb:f7a1:38ec::/64
$ curl -s https://sunknudsen.com/static/media/privacy-guides/how-to-self-host-hardened-strongswan-ikev2-ipsec-vpn-server-for-ios-and-macos/ulagen.py | python3 | grep "First subnet" | awk '{print "STRONGSWAN_IPV6_ULA="$3}' | tee -a ~/.bashrc
STRONGSWAN_IPV6_ULA=fdba:8ce0:c301::/64
$ source ~/.bashrc
```

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import hashlib
import time
@ -16,13 +16,13 @@ def time_ntpformat():
def main():
h = hashlib.sha1()
h.update(get_eui64() + str(time_ntpformat()))
h.update(str(get_eui64() + str(time_ntpformat())).encode("utf-8"))
globalid = h.hexdigest()[0:10]
prefix = ":".join(("fd" + globalid[0:2], globalid[2:6], globalid[6:10]))
print "Prefix: " + prefix + "::/48"
print "First subnet: " + prefix + "::/64"
print "Last subnet: " + prefix + ":ffff::/64"
print("Prefix: " + prefix + "::/48")
print("First subnet: " + prefix + "::/64")
print("Last subnet: " + prefix + ":ffff::/64")
if __name__ == "__main__":
main()