|
1 | | -l |
| 1 | +import requests |
| 2 | + |
| 3 | +def samarkan_info_ip(ip): |
| 4 | + try: |
| 5 | + response = requests.get(f"http://ipinfo.io/{ip}/json").json() |
| 6 | + |
| 7 | + if 'ip' in response and 'city' in response and 'region' in response and 'country' in response and 'loc' in response and 'org' in response and 'postal' in response and 'timezone' in response: |
| 8 | + ip_samaran = ".".join([response['ip'].split('.')[0], response['ip'].split('.')[1], 'xx', 'xx']) |
| 9 | + city_samaran = response['city'][:2] + '**' |
| 10 | + region_samaran = response['region'][:2] + '**' |
| 11 | + country_samaran = response['country'] |
| 12 | + loc_samaran = 'xx.xxxx,xxx.xxxx' |
| 13 | + org_samaran = response['org'][:5] + '*****' |
| 14 | + postal_samaran = response['postal'][:2] + '***' |
| 15 | + timezone_samaran = response['timezone'].split('/')[0] + '/**' |
| 16 | + |
| 17 | + info_samaran = { |
| 18 | + 'ip': ip_samaran, |
| 19 | + 'city': city_samaran, |
| 20 | + 'region': region_samaran, |
| 21 | + 'country': country_samaran, |
| 22 | + 'loc': loc_samaran, |
| 23 | + 'org': org_samaran, |
| 24 | + 'postal': postal_samaran, |
| 25 | + 'timezone': timezone_samaran |
| 26 | + } |
| 27 | + |
| 28 | + return info_samaran |
| 29 | + else: |
| 30 | + return "Informasi IP tidak lengkap" |
| 31 | + |
| 32 | + except requests.exceptions.RequestException as e: |
| 33 | + return "Gagal menghubungi API" |
| 34 | + except Exception as e: |
| 35 | + return "Terjadi kesalahan" |
| 36 | + |
| 37 | +ip_asli = "103.133.61.54" |
| 38 | +info_samaran = samarkan_info_ip(ip_asli) |
| 39 | + |
| 40 | +if isinstance(info_samaran, dict): |
| 41 | + for key, value in info_samaran.items(): |
| 42 | + print(f"{key.capitalize()}: {value}") |
| 43 | +else: |
| 44 | + print(info_samaran) |
0 commit comments