Skip to content

Commit 86cf57b

Browse files
author
Inbal Tako
committed
Clean ip extraction
1 parent 4cf653b commit 86cf57b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ requests~=2.24.0
22
pycryptodome==3.9.8
33
responses==0.10.15
44
requests-mock==1.8.0
5-
pytest==5.4.3
5+
pytest==5.4.3
6+
setuptools~=49.6.0
7+
IPy~=1.0

securenative/utils/ip_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ipaddress
22
import re
3-
import socket
3+
from IPy import IP
44

55

66
class IpUtils(object):
@@ -19,12 +19,12 @@ def is_ip_address(ip_address):
1919
def is_valid_public_ip(ip_address):
2020
ip = ipaddress.ip_address(ip_address)
2121

22-
if ip is ipaddress.IPv4Address:
23-
if not ip.is_loopback and not ip.is_reserved and not ip.is_unspecified:
22+
if ip.version is 4:
23+
if not ip.is_loopback and not ip.is_reserved and not ip.is_unspecified and IP(ip_address).iptype() is not "PRIVATE":
2424
return True
2525
return False
2626

27-
if not ip.is_unspecified:
27+
if not ip.is_unspecified and IP(ip_address).iptype() is not "PRIVATE":
2828
return True
2929
return False
3030

0 commit comments

Comments
 (0)