Skip to content

Commit

Permalink
Merge branch 'moloch--:master' into feature/apiv2
Browse files Browse the repository at this point in the history
  • Loading branch information
Benouare authored Jan 2, 2025
2 parents 5b9b474 + 2c9086e commit f0c8f0a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions models/IpAddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from builtins import str
from uuid import uuid4

from netaddr import IPAddress
from ipaddress import ip_address
from sqlalchemy import Column, ForeignKey
from sqlalchemy.types import Boolean, Integer, String

Expand Down Expand Up @@ -87,26 +87,26 @@ def address(self):
@address.setter
def address(self, value):
try:
ip = IPAddress(self.ipformat(value))
ip = ip_address(self.ipformat(value))
except:
raise ValidationError("Invalid IP Address")
if ip.is_loopback():
if ip.is_loopback:
raise ValidationError("You cannot use a loopback address")
if ip.is_multicast():
if ip.is_multicast:
raise ValidationError("You cannot use a multicast address")
self._address = value

@property
def version(self):
if self._ip_address is None:
self._ip_address = IPAddress(self.ipformat(self._address))
self._ip_address = ip_address(self.ipformat(self._address))
return self._ip_address.version

@property
def is_private(self):
if self._ip_address is None:
self._ip_address = IPAddress(self.ipformat(self._address))
return self._ip_address.is_private()
self._ip_address = ip_address(self.ipformat(self._address))
return self._ip_address.is_private

def to_xml(self, parent):
ip_elem = ET.SubElement(parent, "ip")
Expand Down

0 comments on commit f0c8f0a

Please sign in to comment.