File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -85,16 +85,16 @@ def dedupe(indicators: list[Indicator]) -> list[Indicator]:
8585
8686def classify_ip (address : ipaddress ._BaseAddress ) -> tuple [str , ...]:
8787 tags = ["network" ]
88- if address .is_private :
89- tags .append ("private-ip" )
90- elif address .is_loopback :
88+ if address .is_loopback :
9189 tags .append ("loopback-ip" )
9290 elif address .is_multicast :
9391 tags .append ("multicast-ip" )
9492 elif address .is_reserved :
9593 tags .append ("reserved-ip" )
9694 elif address .is_unspecified :
9795 tags .append ("unspecified-ip" )
96+ elif address .is_private :
97+ tags .append ("private-ip" )
9898 else :
9999 tags .append ("public-ip" )
100100 return tuple (tags )
Original file line number Diff line number Diff line change 33import unittest
44from pathlib import Path
55
6- from iocraft .extractors import extract_from_paths , extract_from_text
6+ from iocraft .extractors import classify_ip , extract_from_paths , extract_from_text
7+ import ipaddress
78
89
910ROOT = Path (__file__ ).resolve ().parents [1 ]
@@ -37,6 +38,19 @@ def test_dedupe(self) -> None:
3738 domains = [indicator for indicator in indicators if indicator .type == "domain" ]
3839 self .assertEqual (len (domains ), 1 )
3940
41+ def test_ip_classification_prefers_specific_tags (self ) -> None :
42+ cases = {
43+ "127.0.0.1" : "loopback-ip" ,
44+ "0.0.0.0" : "unspecified-ip" ,
45+ "224.0.0.1" : "multicast-ip" ,
46+ "240.0.0.1" : "reserved-ip" ,
47+ "10.0.0.1" : "private-ip" ,
48+ "8.8.8.8" : "public-ip" ,
49+ }
50+ for value , expected_tag in cases .items ():
51+ with self .subTest (value = value ):
52+ self .assertIn (expected_tag , classify_ip (ipaddress .ip_address (value )))
53+
4054
4155if __name__ == "__main__" :
4256 unittest .main ()
You can’t perform that action at this time.
0 commit comments