-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckIP.py
38 lines (29 loc) · 941 Bytes
/
CheckIP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# import ipaddress
# def is_internal_ip(ip):
# try:
# ip_obj = ipaddress.ip_address(ip)
# # Check if it's private
# if ip_obj.is_private:
# return f"{ip} is internal (private)"
# else:
# return f"{ip} is external (public)"
# except ValueError:
# return f"{ip} is not a valid IP address"
# # Example IPs
# ips = ["192.168.54.1", "172.26.171.14", "8.8.8.8", "123.45.67.89"]
# for ip in ips:
# print(is_internal_ip(ip))
import ipaddress
def is_internal_ip(ip):
try:
ip_obj = ipaddress.ip_address(ip)
# Check if it's private
if ip_obj.is_private:
return f"{ip} is internal (private)"
else:
return f"{ip} is external (public)"
except ValueError:
return f"{ip} is not a valid IP address"
# Ask the user for an IP address
ip = input("Please enter an IP address: ")
print(is_internal_ip(ip))