ipspot 0.3__py3-none-any.whl → 0.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ipspot/__init__.py +2 -1
- ipspot/cli.py +70 -15
- ipspot/ipv4.py +492 -122
- ipspot/ipv6.py +245 -0
- ipspot/params.py +29 -6
- ipspot/utils.py +41 -2
- {ipspot-0.3.dist-info → ipspot-0.5.dist-info}/METADATA +167 -30
- ipspot-0.5.dist-info/RECORD +14 -0
- {ipspot-0.3.dist-info → ipspot-0.5.dist-info}/WHEEL +1 -1
- {ipspot-0.3.dist-info → ipspot-0.5.dist-info}/licenses/AUTHORS.md +2 -0
- ipspot-0.3.dist-info/RECORD +0 -13
- {ipspot-0.3.dist-info → ipspot-0.5.dist-info}/entry_points.txt +0 -0
- {ipspot-0.3.dist-info → ipspot-0.5.dist-info}/licenses/LICENSE +0 -0
- {ipspot-0.3.dist-info → ipspot-0.5.dist-info}/top_level.txt +0 -0
ipspot/__init__.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
"""ipspot modules."""
|
|
3
|
-
from .params import IPSPOT_VERSION, IPv4API
|
|
3
|
+
from .params import IPSPOT_VERSION, IPv4API, IPv6API
|
|
4
4
|
from .ipv4 import get_private_ipv4, get_public_ipv4, is_ipv4
|
|
5
|
+
from .ipv6 import get_private_ipv6, get_public_ipv6, is_ipv6
|
|
5
6
|
from .utils import is_loopback
|
|
6
7
|
__version__ = IPSPOT_VERSION
|
ipspot/cli.py
CHANGED
|
@@ -4,8 +4,9 @@ import argparse
|
|
|
4
4
|
from typing import Union, Tuple
|
|
5
5
|
from art import tprint
|
|
6
6
|
from .ipv4 import get_public_ipv4, get_private_ipv4
|
|
7
|
-
from .
|
|
8
|
-
from .
|
|
7
|
+
from .ipv6 import get_public_ipv6, get_private_ipv6
|
|
8
|
+
from .utils import _filter_parameter
|
|
9
|
+
from .params import IPv4API, IPv6API, PARAMETERS_NAME_MAP
|
|
9
10
|
from .params import IPSPOT_OVERVIEW, IPSPOT_REPO, IPSPOT_VERSION
|
|
10
11
|
|
|
11
12
|
|
|
@@ -17,34 +18,72 @@ def ipspot_info() -> None: # pragma: no cover
|
|
|
17
18
|
print("Repo : " + IPSPOT_REPO)
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
def display_ip_info(ipv4_api: IPv4API = IPv4API.
|
|
21
|
-
|
|
21
|
+
def display_ip_info(ipv4_api: IPv4API = IPv4API.AUTO_SAFE,
|
|
22
|
+
ipv6_api: IPv6API = IPv6API.AUTO_SAFE,
|
|
23
|
+
geo: bool=False,
|
|
24
|
+
timeout: Union[float, Tuple[float, float]]=5,
|
|
25
|
+
max_retries: int = 0, retry_delay: float = 1.0) -> None: # pragma: no cover
|
|
22
26
|
"""
|
|
23
27
|
Print collected IP and location data.
|
|
24
28
|
|
|
25
29
|
:param ipv4_api: public IPv4 API
|
|
30
|
+
:param ipv6_api: public IPv6 API
|
|
26
31
|
:param geo: geolocation flag
|
|
27
32
|
:param timeout: timeout value for API
|
|
33
|
+
:param max_retries: number of retries
|
|
34
|
+
:param retry_delay: delay between retries (in seconds)
|
|
28
35
|
"""
|
|
29
|
-
private_result = get_private_ipv4()
|
|
30
36
|
print("Private IP:\n")
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
private_ipv4_result = get_private_ipv4()
|
|
38
|
+
if private_ipv4_result["status"]:
|
|
39
|
+
private_ipv4 = private_ipv4_result["data"]["ip"]
|
|
40
|
+
else:
|
|
41
|
+
private_ipv4 = private_ipv4_result["error"]
|
|
42
|
+
print(" IPv4: {private_ipv4}\n".format(private_ipv4=private_ipv4))
|
|
43
|
+
|
|
44
|
+
private_ipv6_result = get_private_ipv6()
|
|
45
|
+
if private_ipv6_result["status"]:
|
|
46
|
+
private_ipv6 = private_ipv6_result["data"]["ip"]
|
|
47
|
+
else:
|
|
48
|
+
private_ipv6 = private_ipv6_result["error"]
|
|
49
|
+
print(" IPv6: {private_ipv6}".format(private_ipv6=private_ipv6))
|
|
33
50
|
|
|
34
51
|
public_title = "\nPublic IP"
|
|
35
52
|
if geo:
|
|
36
53
|
public_title += " and Location Info"
|
|
37
54
|
public_title += ":\n"
|
|
38
55
|
print(public_title)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
56
|
+
print(" IPv4:\n")
|
|
57
|
+
public_ipv4_result = get_public_ipv4(
|
|
58
|
+
ipv4_api,
|
|
59
|
+
geo=geo,
|
|
60
|
+
timeout=timeout,
|
|
61
|
+
max_retries=max_retries,
|
|
62
|
+
retry_delay=retry_delay)
|
|
63
|
+
if public_ipv4_result["status"]:
|
|
64
|
+
for name, parameter in sorted(public_ipv4_result["data"].items()):
|
|
65
|
+
print(
|
|
66
|
+
" {name}: {parameter}".format(
|
|
67
|
+
name=PARAMETERS_NAME_MAP[name],
|
|
68
|
+
parameter=_filter_parameter(parameter)))
|
|
69
|
+
else:
|
|
70
|
+
print(" Error: {public_ipv4_result[error]}".format(public_ipv4_result=public_ipv4_result))
|
|
71
|
+
|
|
72
|
+
print("\n IPv6:\n")
|
|
73
|
+
public_ipv6_result = get_public_ipv6(
|
|
74
|
+
ipv6_api,
|
|
75
|
+
geo=geo,
|
|
76
|
+
timeout=timeout,
|
|
77
|
+
max_retries=max_retries,
|
|
78
|
+
retry_delay=retry_delay)
|
|
79
|
+
if public_ipv6_result["status"]:
|
|
80
|
+
for name, parameter in sorted(public_ipv6_result["data"].items()):
|
|
42
81
|
print(
|
|
43
|
-
"
|
|
82
|
+
" {name}: {parameter}".format(
|
|
44
83
|
name=PARAMETERS_NAME_MAP[name],
|
|
45
|
-
parameter=
|
|
84
|
+
parameter=_filter_parameter(parameter)))
|
|
46
85
|
else:
|
|
47
|
-
print("
|
|
86
|
+
print(" Error: {public_ipv6_result[error]}".format(public_ipv6_result=public_ipv6_result))
|
|
48
87
|
|
|
49
88
|
|
|
50
89
|
def main() -> None: # pragma: no cover
|
|
@@ -56,11 +95,20 @@ def main() -> None: # pragma: no cover
|
|
|
56
95
|
type=str.lower,
|
|
57
96
|
choices=[
|
|
58
97
|
x.value for x in IPv4API],
|
|
59
|
-
default=IPv4API.
|
|
98
|
+
default=IPv4API.AUTO_SAFE.value)
|
|
99
|
+
parser.add_argument(
|
|
100
|
+
'--ipv6-api',
|
|
101
|
+
help='public IPv6 API',
|
|
102
|
+
type=str.lower,
|
|
103
|
+
choices=[
|
|
104
|
+
x.value for x in IPv6API],
|
|
105
|
+
default=IPv6API.AUTO_SAFE.value)
|
|
60
106
|
parser.add_argument('--info', help='info', nargs="?", const=1)
|
|
61
107
|
parser.add_argument('--version', help='version', nargs="?", const=1)
|
|
62
108
|
parser.add_argument('--no-geo', help='no geolocation data', nargs="?", const=1, default=False)
|
|
63
109
|
parser.add_argument('--timeout', help='timeout for the API request', type=float, default=5.0)
|
|
110
|
+
parser.add_argument('--max-retries', help='number of retries', type=int, default=0)
|
|
111
|
+
parser.add_argument('--retry-delay', help='delay between retries (in seconds)', type=float, default=1.0)
|
|
64
112
|
|
|
65
113
|
args = parser.parse_args()
|
|
66
114
|
if args.version:
|
|
@@ -69,5 +117,12 @@ def main() -> None: # pragma: no cover
|
|
|
69
117
|
ipspot_info()
|
|
70
118
|
else:
|
|
71
119
|
ipv4_api = IPv4API(args.ipv4_api)
|
|
120
|
+
ipv6_api = IPv6API(args.ipv6_api)
|
|
72
121
|
geo = not args.no_geo
|
|
73
|
-
display_ip_info(
|
|
122
|
+
display_ip_info(
|
|
123
|
+
ipv4_api=ipv4_api,
|
|
124
|
+
ipv6_api=ipv6_api,
|
|
125
|
+
geo=geo,
|
|
126
|
+
timeout=args.timeout,
|
|
127
|
+
max_retries=args.max_retries,
|
|
128
|
+
retry_delay=args.retry_delay)
|