Ip Address: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
except Exception as e: | except Exception as e: | ||
print(f'Gagal mendapatkan IP publik. Kesalahan: {e}') | print(f'Gagal mendapatkan IP publik. Kesalahan: {e}') | ||
if __name__ == "__main__": | if __name__ == "__main__": | ||
get_public_ip() | get_public_ip() | ||
jangan lupa pip install requests | jangan lupa pip install requests |
Revision as of 00:51, 30 November 2023
Public
Berikut scirpt cek ip public
import requests
def get_public_ip():
try: # Menggunakan layanan httpbin response = requests.get('https://httpbin.org/ip') ip = response.json()['origin'] print(f'IP publik Anda adalah: {ip}') except Exception as e: print(f'Gagal mendapatkan IP publik. Kesalahan: {e}') if __name__ == "__main__": get_public_ip()
jangan lupa pip install requests