From 395ceb8787d3b394367947d6ab10b186eba02353 Mon Sep 17 00:00:00 2001 From: Allen Joseph G <63872540+unknownhackerworld@users.noreply.github.com> Date: Thu, 5 Nov 2026 20:49:41 +0000 Subject: [PATCH] Fix created/updated dates and address in RDAP whois nets _create_net reset both created and updated on every RDAP event, and mapped "last changed" to created and "registration" to updated. With ARIN's usual event order (last changed, then registration) the net ended up with created=None and updated set to the registration date. Map "registration" to created and "last changed" to updated, matching the ipwhois field meaning, and stop resetting the value on other events. The address was also overwritten by every entity, so a trailing entity without an address cleared the registrant's address. Keep the first address found. Treat events and entities as optional, since RDAP does not require them. Signed-off-by: Allen Joseph G <63872540+unknownhackerworld@users.noreply.github.com> --- msticpy/context/ip_utils.py | 12 ++++++++---- tests/context/test_ip_utils.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/msticpy/context/ip_utils.py b/msticpy/context/ip_utils.py index 5d0c9526..2ef89507 100644 --- a/msticpy/context/ip_utils.py +++ b/msticpy/context/ip_utils.py @@ -690,11 +690,15 @@ def _create_net(data: dict[str, Any]) -> dict[str, Any]: address: str | None = None created: str | None = None updated: str | None = None - for item in data["events"]: - created = item["eventDate"] if item["eventAction"] == "last changed" else None - updated = item["eventDate"] if item["eventAction"] == "registration" else None - for entity in data["entities"]: + for item in data.get("events", []): + if item.get("eventAction") == "registration": + created = item.get("eventDate") + elif item.get("eventAction") == "last changed": + updated = item.get("eventDate") + for entity in data.get("entities", []): address = _find_address(entity) + if address: + break regex = r"[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*" emails: list[str] = re.findall(regex, str(data)) return { diff --git a/tests/context/test_ip_utils.py b/tests/context/test_ip_utils.py index a950be12..c045bdf4 100644 --- a/tests/context/test_ip_utils.py +++ b/tests/context/test_ip_utils.py @@ -15,6 +15,7 @@ import msticpy.init.mp_pandas_accessors # noqa: F401 from msticpy.context.ip_utils import ( + _create_net, _IpWhoIsResult, _whois_lookup, get_asn_details, @@ -535,3 +536,35 @@ def test_asn_query_features(mock_asn_whois_query): check.is_in("AS3598", asn_name_details.keys()) check.is_instance(asn_name_details, dict) check.equal(asn_name_details["AS3598"], "MICROSOFT-CORP-AS, US") + + +def test_create_net_event_dates_and_address(): + """Test RDAP events map to created/updated and address is kept.""" + net = _create_net(RDAP_RESPONSE) + check.equal(net["created"], "2015-03-26T13:58:18-04:00") + check.equal(net["updated"], "2021-12-14T20:28:53-05:00") + check.equal(net["address"], "One Microsoft Way\nRedmond\nWA\n98052\nUnited States") + + # Event order should not matter. + reordered = {**RDAP_RESPONSE, "events": list(reversed(RDAP_RESPONSE["events"]))} + net = _create_net(reordered) + check.equal(net["created"], "2015-03-26T13:58:18-04:00") + check.equal(net["updated"], "2021-12-14T20:28:53-05:00") + + # A later entity without an address should not clear an earlier one. + no_addr_entity = {"handle": "NOADDR", "vcardArray": ["vcard", []]} + extra_entity = { + **RDAP_RESPONSE, + "entities": [*RDAP_RESPONSE["entities"], no_addr_entity], + } + net = _create_net(extra_entity) + check.equal(net["address"], "One Microsoft Way\nRedmond\nWA\n98052\nUnited States") + + # Events and entities are optional in RDAP responses. + minimal = { + k: v for k, v in RDAP_RESPONSE.items() if k not in ("events", "entities") + } + net = _create_net(minimal) + check.is_none(net["created"]) + check.is_none(net["updated"]) + check.is_none(net["address"])