Skip to content

Commit

Permalink
Initial commit: use ipaddress standard library to validate IP address (
Browse files Browse the repository at this point in the history
…#150)

Co-authored-by: Marta Gómez Macías <[email protected]>
  • Loading branch information
za and mgmacias95 authored Aug 3, 2023
1 parent 36c0102 commit 66846b8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions examples/suspicious_network_observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@

import argparse
import asyncio
import ipaddress
import re
import vt


IP_REGEX = re.compile(r'\d+\.\d+\.\d+\.\d+')


def is_ip_address(netloc):
"""Checks whether a given value is a IP address or not.
Expand All @@ -36,7 +34,12 @@ def is_ip_address(netloc):
Returns:
True or false
"""
return IP_REGEX.match(netloc) is not None
try:
ipaddress.ip_address(netloc)
except ValueError:
return False
else:
return True


def get_detection_rate(stats):
Expand Down

0 comments on commit 66846b8

Please sign in to comment.