https://dev.kronoz.win/r/marzneshin.git
| 1 |
a47eb4c |
Dawsh |
2y ago |
import math |
| 2 |
a47eb4c |
Dawsh |
2y ago |
import socket |
| 3 |
a47eb4c |
Dawsh |
2y ago |
|
| 4 |
a47eb4c |
Dawsh |
2y ago |
|
| 5 |
a47eb4c |
Dawsh |
2y ago |
def get_public_ip(): |
| 6 |
a47eb4c |
Dawsh |
2y ago |
try: |
| 7 |
a47eb4c |
Dawsh |
2y ago |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 8 |
01cdf2e |
Dawsh |
2y ago |
sock.connect(("8.8.8.8", 80)) |
| 9 |
a47eb4c |
Dawsh |
2y ago |
return sock.getsockname()[0] |
| 10 |
a47eb4c |
Dawsh |
2y ago |
except (socket.error, IndexError): |
| 11 |
a47eb4c |
Dawsh |
2y ago |
pass |
| 12 |
a47eb4c |
Dawsh |
2y ago |
finally: |
| 13 |
a47eb4c |
Dawsh |
2y ago |
sock.close() |
| 14 |
a47eb4c |
Dawsh |
2y ago |
|
| 15 |
01cdf2e |
Dawsh |
2y ago |
return "127.0.0.1" |
| 16 |
a47eb4c |
Dawsh |
2y ago |
|
| 17 |
a47eb4c |
Dawsh |
2y ago |
|
| 18 |
a47eb4c |
Dawsh |
2y ago |
def readable_size(size_bytes): |
| 19 |
a47eb4c |
Dawsh |
2y ago |
if size_bytes == 0: |
| 20 |
a47eb4c |
Dawsh |
2y ago |
return "0 B" |
| 21 |
a47eb4c |
Dawsh |
2y ago |
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") |
| 22 |
a47eb4c |
Dawsh |
2y ago |
i = int(math.floor(math.log(size_bytes, 1024))) |
| 23 |
a47eb4c |
Dawsh |
2y ago |
p = math.pow(1024, i) |
| 24 |
a47eb4c |
Dawsh |
2y ago |
s = round(size_bytes / p, 2) |
| 25 |
01cdf2e |
Dawsh |
2y ago |
return f"{s} {size_name[i]}" |