1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-08-08 22:36:48 +02:00

use jc.utils.timestamp() for datetime conversions

This commit is contained in:
Kelly Brazil
2024-10-20 09:45:08 -07:00
parent 6072ea0ec7
commit 26133261f9
7 changed files with 23 additions and 607 deletions

View File

@ -72,8 +72,12 @@ Schema:
string string
], ],
"primary_wins_server": string, "primary_wins_server": string,
"lease_expires": string, # [0] "lease_expires": string,
"lease_obtained": string, # [0] "lease_expires_epoch": integer, # [0]
"lease_expires_iso": string,
"lease_obtained": string,
"lease_obtained_epoch": integer, # [0]
"lease_obtained_iso": string,
"netbios_over_tcpip": boolean, "netbios_over_tcpip": boolean,
"media_state": string, "media_state": string,
"extras": [ "extras": [
@ -85,9 +89,8 @@ Schema:
} }
Notes: Notes:
[0] - 'lease_expires' and 'lease_obtained' are parsed to ISO8601 [0] - The epoch calculated timestamp field is naive. (i.e. based on
format date strings. if the value was unable to be parsed by the local time of the system the parser is run on)
datetime, the fields will be in their raw form
[1] - 'autoconfigured' under 'ipv4_address' is only providing [1] - 'autoconfigured' under 'ipv4_address' is only providing
indication if the ipv4 address was labeled as "Autoconfiguration indication if the ipv4 address was labeled as "Autoconfiguration
IPv4 Address" vs "IPv4 Address". It does not infer any IPv4 Address" vs "IPv4 Address". It does not infer any
@ -529,17 +532,15 @@ def _process(proc_data):
if "netbios_over_tcpip" in adapter and adapter["netbios_over_tcpip"] is not None: if "netbios_over_tcpip" in adapter and adapter["netbios_over_tcpip"] is not None:
adapter["netbios_over_tcpip"] = (adapter["netbios_over_tcpip"].lower() == "enabled") adapter["netbios_over_tcpip"] = (adapter["netbios_over_tcpip"].lower() == "enabled")
if "lease_expires" in adapter and adapter["lease_expires"] is not None and adapter["lease_expires"] != "": if "lease_expires" in adapter and adapter["lease_expires"]:
try: ts = jc.utils.timestamp(adapter['lease_expires'], format_hint=(1720,))
adapter["lease_expires"] = datetime.strptime(adapter["lease_expires"], "%A, %B %d, %Y %I:%M:%S %p").isoformat() adapter["lease_expires_epoch"] = ts.naive
except: adapter["lease_expires_iso"] = ts.iso
pass # Leave date in raw format if not parseable
if "lease_obtained" in adapter and adapter["lease_obtained"] is not None and adapter["lease_obtained"] != "": if "lease_obtained" in adapter and adapter["lease_obtained"]:
try: ts = jc.utils.timestamp(adapter['lease_obtained'], format_hint=(1720,))
adapter["lease_obtained"] = datetime.strptime(adapter["lease_obtained"], "%A, %B %d, %Y %I:%M:%S %p").isoformat() adapter["lease_obtained_epoch"] = ts.naive
except: adapter["lease_obtained_iso"] = ts.iso
pass # Leave date in raw format if not parseable
adapter["link_local_ipv6_addresses"] = [_process_ipv6_address(address) for address in adapter.get("link_local_ipv6_addresses", [])] adapter["link_local_ipv6_addresses"] = [_process_ipv6_address(address) for address in adapter.get("link_local_ipv6_addresses", [])]
adapter["ipv4_addresses"] = [_process_ipv4_address(address) for address in adapter.get("ipv4_addresses", [])] adapter["ipv4_addresses"] = [_process_ipv4_address(address) for address in adapter.get("ipv4_addresses", [])]

View File

@ -696,6 +696,7 @@ class timestamp:
{'id': 1700, 'format': '%m/%d/%Y, %I:%M:%S %p', 'locale': None}, # Windows english format wint non-UTC tz (found in systeminfo cli output): 3/22/2021, 1:15:51 PM (UTC-0600) {'id': 1700, 'format': '%m/%d/%Y, %I:%M:%S %p', 'locale': None}, # Windows english format wint non-UTC tz (found in systeminfo cli output): 3/22/2021, 1:15:51 PM (UTC-0600)
{'id': 1705, 'format': '%m/%d/%Y, %I:%M:%S %p %Z', 'locale': None}, # Windows english format with UTC tz (found in systeminfo cli output): 3/22/2021, 1:15:51 PM (UTC) {'id': 1705, 'format': '%m/%d/%Y, %I:%M:%S %p %Z', 'locale': None}, # Windows english format with UTC tz (found in systeminfo cli output): 3/22/2021, 1:15:51 PM (UTC)
{'id': 1710, 'format': '%m/%d/%Y, %I:%M:%S %p UTC%z', 'locale': None}, # Windows english format with UTC tz (found in systeminfo cli output): 3/22/2021, 1:15:51 PM (UTC+0000) {'id': 1710, 'format': '%m/%d/%Y, %I:%M:%S %p UTC%z', 'locale': None}, # Windows english format with UTC tz (found in systeminfo cli output): 3/22/2021, 1:15:51 PM (UTC+0000)
{'id': 1720, 'format': '%A, %B %d, %Y %I:%M:%S %p', 'locale': None}, # ipconfig cli output format: Thursday, June 22, 2023 10:39:04 AM
{'id': 1750, 'format': '%Y/%m/%d-%H:%M:%S.%f', 'locale': None}, # Google Big Table format with no timezone: 1970/01/01-01:00:00.000000 {'id': 1750, 'format': '%Y/%m/%d-%H:%M:%S.%f', 'locale': None}, # Google Big Table format with no timezone: 1970/01/01-01:00:00.000000
{'id': 1755, 'format': '%Y/%m/%d-%H:%M:%S.%f%z', 'locale': None}, # Google Big Table format with timezone: 1970/01/01-01:00:00.000000+00:00 {'id': 1755, 'format': '%Y/%m/%d-%H:%M:%S.%f%z', 'locale': None}, # Google Big Table format with timezone: 1970/01/01-01:00:00.000000+00:00
{'id': 1760, 'format': '%Y-%m-%d %H:%M:%S%z', 'locale': None}, # certbot format with timezone: 2023-06-12 01:35:30+00:00 {'id': 1760, 'format': '%Y-%m-%d %H:%M:%S%z', 'locale': None}, # certbot format with timezone: 2023-06-12 01:35:30+00:00

View File

@ -1,133 +1 @@
{ {"host_name":"DESKTOP-WIN10-PRO","primary_dns_suffix":null,"node_type":"Hybrid","ip_routing_enabled":false,"wins_proxy_enabled":false,"dns_suffix_search_list":["tailff123.ts.net","internal.companyname.com"],"adapters":[{"name_long":"Unknown adapter Tailscale","name":"Tailscale","type":"Unknown","connection_specific_dns_suffix":"tailff123.ts.net","connection_specific_dns_suffix_search_list":["tailff123.ts.net"],"description":"Tailscale Tunnel","physical_address":null,"dhcp_enabled":false,"autoconfiguration_enabled":true,"ipv6_addresses":[{"address":"fd7a:115c:a1e0:ab12:4843:cd96:6293:47b2","status":"Preferred"}],"temporary_ipv6_addresses":[],"link_local_ipv6_addresses":[{"address":"fe80::99d0:ec2d:b2e7:536b","prefix_length":8,"status":"Preferred"}],"ipv4_addresses":[{"address":"100.115.71.66","subnet_mask":"255.255.255.255","status":"Preferred","autoconfigured":false}],"default_gateways":[],"dhcp_server":null,"dhcpv6_iaid":null,"dhcpv6_client_duid":null,"dns_servers":["fec0:0:0:ffff::1%1","fec0:0:0:ffff::2%1","fec0:0:0:ffff::3%1"],"primary_wins_server":null,"lease_expires":null,"lease_obtained":null,"netbios_over_tcpip":true,"media_state":null,"extras":[]},{"name_long":"Ethernet adapter Ethernet 2","name":"Ethernet 2","type":"Ethernet","connection_specific_dns_suffix":"internal.companyname.com","connection_specific_dns_suffix_search_list":[],"description":"ASIX AX88179 USB 3.0 to Gigabit Ethernet Adapter #2","physical_address":"F8-E4-3B-AD-F2-6D","dhcp_enabled":true,"autoconfiguration_enabled":true,"ipv6_addresses":[],"temporary_ipv6_addresses":[],"link_local_ipv6_addresses":[{"address":"fe80::c936:c2db:79ad:e1c6","prefix_length":16,"status":"Preferred"}],"ipv4_addresses":[{"address":"10.50.13.132","subnet_mask":"255.255.255.0","status":"Preferred","autoconfigured":false}],"default_gateways":["10.50.13.1"],"dhcp_server":"10.50.13.1","dhcpv6_iaid":"351866565","dhcpv6_client_duid":"00-01-00-01-2A-15-C3-11-1C-D3-05-F1-58-E1","dns_servers":["10.50.13.1"],"primary_wins_server":null,"lease_expires":"Monday, September 23, 2024 2:31:46 AM","lease_obtained":"Thursday, June 22, 2023 10:39:04 AM","netbios_over_tcpip":true,"media_state":null,"extras":[],"lease_expires_epoch":1727083906,"lease_expires_iso":"2024-09-23T02:31:46","lease_obtained_epoch":1687455544,"lease_obtained_iso":"2023-06-22T10:39:04"},{"name_long":"Ethernet adapter Bluetooth Network Connection","name":"Bluetooth Network Connection","type":"Ethernet","connection_specific_dns_suffix":null,"connection_specific_dns_suffix_search_list":[],"description":"Bluetooth Device (Personal Area Network)","physical_address":"1C-C1-0C-C3-25-B4","dhcp_enabled":true,"autoconfiguration_enabled":true,"ipv6_addresses":[],"temporary_ipv6_addresses":[],"link_local_ipv6_addresses":[],"ipv4_addresses":[],"default_gateways":[],"dhcp_server":null,"dhcpv6_iaid":null,"dhcpv6_client_duid":null,"dns_servers":[],"primary_wins_server":null,"lease_expires":null,"lease_obtained":null,"netbios_over_tcpip":null,"media_state":"Media disconnected","extras":[]}],"extras":[]}
"host_name": "DESKTOP-WIN10-PRO",
"primary_dns_suffix": null,
"node_type": "Hybrid",
"ip_routing_enabled": false,
"wins_proxy_enabled": false,
"dns_suffix_search_list": [
"tailff123.ts.net",
"internal.companyname.com"
],
"adapters": [
{
"name_long": "Unknown adapter Tailscale",
"name": "Tailscale",
"type": "Unknown",
"connection_specific_dns_suffix": "tailff123.ts.net",
"connection_specific_dns_suffix_search_list": [
"tailff123.ts.net"
],
"description": "Tailscale Tunnel",
"physical_address": null,
"dhcp_enabled": false,
"autoconfiguration_enabled": true,
"ipv6_addresses": [
{
"address": "fd7a:115c:a1e0:ab12:4843:cd96:6293:47b2",
"status": "Preferred"
}
],
"temporary_ipv6_addresses": [],
"link_local_ipv6_addresses": [
{
"address": "fe80::99d0:ec2d:b2e7:536b",
"prefix_length": 8,
"status": "Preferred"
}
],
"ipv4_addresses": [
{
"address": "100.115.71.66",
"subnet_mask": "255.255.255.255",
"status": "Preferred",
"autoconfigured": false
}
],
"default_gateways": [],
"dhcp_server": null,
"dhcpv6_iaid": null,
"dhcpv6_client_duid": null,
"dns_servers": [
"fec0:0:0:ffff::1%1",
"fec0:0:0:ffff::2%1",
"fec0:0:0:ffff::3%1"
],
"primary_wins_server": null,
"lease_expires": null,
"lease_obtained": null,
"netbios_over_tcpip": true,
"media_state": null,
"extras": []
},
{
"name_long": "Ethernet adapter Ethernet 2",
"name": "Ethernet 2",
"type": "Ethernet",
"connection_specific_dns_suffix": "internal.companyname.com",
"connection_specific_dns_suffix_search_list": [],
"description": "ASIX AX88179 USB 3.0 to Gigabit Ethernet Adapter #2",
"physical_address": "F8-E4-3B-AD-F2-6D",
"dhcp_enabled": true,
"autoconfiguration_enabled": true,
"ipv6_addresses": [],
"temporary_ipv6_addresses": [],
"link_local_ipv6_addresses": [
{
"address": "fe80::c936:c2db:79ad:e1c6",
"prefix_length": 16,
"status": "Preferred"
}
],
"ipv4_addresses": [
{
"address": "10.50.13.132",
"subnet_mask": "255.255.255.0",
"status": "Preferred",
"autoconfigured": false
}
],
"default_gateways": [
"10.50.13.1"
],
"dhcp_server": "10.50.13.1",
"dhcpv6_iaid": "351866565",
"dhcpv6_client_duid": "00-01-00-01-2A-15-C3-11-1C-D3-05-F1-58-E1",
"dns_servers": [
"10.50.13.1"
],
"primary_wins_server": null,
"lease_expires": "2024-09-23T02:31:46",
"lease_obtained": "2023-06-22T10:39:04",
"netbios_over_tcpip": true,
"media_state": null,
"extras": []
},
{
"name_long": "Ethernet adapter Bluetooth Network Connection",
"name": "Bluetooth Network Connection",
"type": "Ethernet",
"connection_specific_dns_suffix": null,
"connection_specific_dns_suffix_search_list": [],
"description": "Bluetooth Device (Personal Area Network)",
"physical_address": "1C-C1-0C-C3-25-B4",
"dhcp_enabled": true,
"autoconfiguration_enabled": true,
"ipv6_addresses": [],
"temporary_ipv6_addresses": [],
"link_local_ipv6_addresses": [],
"ipv4_addresses": [],
"default_gateways": [],
"dhcp_server": null,
"dhcpv6_iaid": null,
"dhcpv6_client_duid": null,
"dns_servers": [],
"primary_wins_server": null,
"lease_expires": null,
"lease_obtained": null,
"netbios_over_tcpip": null,
"media_state": "Media disconnected",
"extras": []
}
],
"extras": []
}

File diff suppressed because one or more lines are too long

View File

@ -1,82 +1 @@
{ {"host_name":"DESKTOP-WIN7","primary_dns_suffix":"somecompany.corp","node_type":"Hybrid","ip_routing_enabled":false,"wins_proxy_enabled":false,"dns_suffix_search_list":["somecompany.corp"],"adapters":[{"name_long":"Ethernet adapter Local Area Connection","name":"Local Area Connection","type":"Ethernet","connection_specific_dns_suffix":null,"connection_specific_dns_suffix_search_list":[],"description":"Intel(R) PRO/1000 MT Network Connection","physical_address":"00-0C-29-37-3B-4E","dhcp_enabled":true,"autoconfiguration_enabled":true,"ipv6_addresses":[],"temporary_ipv6_addresses":[],"link_local_ipv6_addresses":[{"address":"fe80::c447:d1ef:c29f:c44c","prefix_length":10,"status":"Preferred"}],"ipv4_addresses":[{"address":"192.168.22.33","subnet_mask":"255.255.255.0","status":"Preferred","autoconfigured":false}],"default_gateways":["192.168.22.1"],"dhcp_server":"192.168.22.1","dhcpv6_iaid":"234881473","dhcpv6_client_duid":"00-01-00-01-29-4E-8F-8A-00-0C-29-88-1B-1F","dns_servers":["192.168.22.151"],"primary_wins_server":null,"lease_expires":"Tuesday, September 24, 2024 7:02:58 AM","lease_obtained":"Friday, September 20, 2024 12:13:59 PM","netbios_over_tcpip":true,"media_state":null,"extras":[],"lease_expires_epoch":1727186578,"lease_expires_iso":"2024-09-24T07:02:58","lease_obtained_epoch":1726859639,"lease_obtained_iso":"2024-09-20T12:13:59"},{"name_long":"Tunnel adapter isatap.{E24F3EA8-436E-3B26-8BB9-CED33928744B}","name":"isatap.{E24F3EA8-436E-3B26-8BB9-CED33928744B}","type":"Tunnel","connection_specific_dns_suffix":null,"connection_specific_dns_suffix_search_list":[],"description":"Microsoft ISATAP Adapter","physical_address":"00-00-00-00-00-00-00-E0","dhcp_enabled":false,"autoconfiguration_enabled":true,"ipv6_addresses":[],"temporary_ipv6_addresses":[],"link_local_ipv6_addresses":[],"ipv4_addresses":[],"default_gateways":[],"dhcp_server":null,"dhcpv6_iaid":null,"dhcpv6_client_duid":null,"dns_servers":[],"primary_wins_server":null,"lease_expires":null,"lease_obtained":null,"netbios_over_tcpip":null,"media_state":"Media disconnected","extras":[]}],"extras":[]}
"host_name": "DESKTOP-WIN7",
"primary_dns_suffix": "somecompany.corp",
"node_type": "Hybrid",
"ip_routing_enabled": false,
"wins_proxy_enabled": false,
"dns_suffix_search_list": [
"somecompany.corp"
],
"adapters": [
{
"name_long": "Ethernet adapter Local Area Connection",
"name": "Local Area Connection",
"type": "Ethernet",
"connection_specific_dns_suffix": null,
"connection_specific_dns_suffix_search_list": [],
"description": "Intel(R) PRO/1000 MT Network Connection",
"physical_address": "00-0C-29-37-3B-4E",
"dhcp_enabled": true,
"autoconfiguration_enabled": true,
"ipv6_addresses": [],
"temporary_ipv6_addresses": [],
"link_local_ipv6_addresses": [
{
"address": "fe80::c447:d1ef:c29f:c44c",
"prefix_length": 10,
"status": "Preferred"
}
],
"ipv4_addresses": [
{
"address": "192.168.22.33",
"subnet_mask": "255.255.255.0",
"status": "Preferred",
"autoconfigured": false
}
],
"default_gateways": [
"192.168.22.1"
],
"dhcp_server": "192.168.22.1",
"dhcpv6_iaid": "234881473",
"dhcpv6_client_duid": "00-01-00-01-29-4E-8F-8A-00-0C-29-88-1B-1F",
"dns_servers": [
"192.168.22.151"
],
"primary_wins_server": null,
"lease_expires": "2024-09-24T07:02:58",
"lease_obtained": "2024-09-20T12:13:59",
"netbios_over_tcpip": true,
"media_state": null,
"extras": []
},
{
"name_long": "Tunnel adapter isatap.{E24F3EA8-436E-3B26-8BB9-CED33928744B}",
"name": "isatap.{E24F3EA8-436E-3B26-8BB9-CED33928744B}",
"type": "Tunnel",
"connection_specific_dns_suffix": null,
"connection_specific_dns_suffix_search_list": [],
"description": "Microsoft ISATAP Adapter",
"physical_address": "00-00-00-00-00-00-00-E0",
"dhcp_enabled": false,
"autoconfiguration_enabled": true,
"ipv6_addresses": [],
"temporary_ipv6_addresses": [],
"link_local_ipv6_addresses": [],
"ipv4_addresses": [],
"default_gateways": [],
"dhcp_server": null,
"dhcpv6_iaid": null,
"dhcpv6_client_duid": null,
"dns_servers": [],
"primary_wins_server": null,
"lease_expires": null,
"lease_obtained": null,
"netbios_over_tcpip": null,
"media_state": "Media disconnected",
"extras": []
}
],
"extras": []
}

View File

@ -1,51 +1 @@
{ {"host_name":"DESKTOP-PC4","primary_dns_suffix":"somecompany.corp","node_type":"Unknown","ip_routing_enabled":false,"wins_proxy_enabled":false,"dns_suffix_search_list":["somecompany.corp","somecompany.xyz"],"adapters":[{"name_long":"Ethernet adapter Local Area Connection","name":"Local Area Connection","type":"Ethernet","connection_specific_dns_suffix":null,"connection_specific_dns_suffix_search_list":[],"description":"Intel(R) PRO/1000 MT Network Connection","physical_address":"00-0C-29-25-B6-4D","dhcp_enabled":true,"autoconfiguration_enabled":true,"ipv6_addresses":[],"temporary_ipv6_addresses":[],"link_local_ipv6_addresses":[],"ipv4_addresses":[{"address":"192.168.22.135","subnet_mask":"255.255.255.0","status":null,"autoconfigured":false}],"default_gateways":["192.168.22.1"],"dhcp_server":"192.168.22.1","dhcpv6_iaid":null,"dhcpv6_client_duid":null,"dns_servers":["192.168.22.151"],"primary_wins_server":null,"lease_expires":"Sunday, September 22, 2024 10:31:26 PM","lease_obtained":"Saturday, September 21, 2024 10:31:26 PM","netbios_over_tcpip":null,"media_state":null,"extras":[],"lease_expires_epoch":1727069486,"lease_expires_iso":"2024-09-22T22:31:26","lease_obtained_epoch":1726983086,"lease_obtained_iso":"2024-09-21T22:31:26"}],"extras":[]}
"host_name": "DESKTOP-PC4",
"primary_dns_suffix": "somecompany.corp",
"node_type": "Unknown",
"ip_routing_enabled": false,
"wins_proxy_enabled": false,
"dns_suffix_search_list": [
"somecompany.corp",
"somecompany.xyz"
],
"adapters": [
{
"name_long": "Ethernet adapter Local Area Connection",
"name": "Local Area Connection",
"type": "Ethernet",
"connection_specific_dns_suffix": null,
"connection_specific_dns_suffix_search_list": [],
"description": "Intel(R) PRO/1000 MT Network Connection",
"physical_address": "00-0C-29-25-B6-4D",
"dhcp_enabled": true,
"autoconfiguration_enabled": true,
"ipv6_addresses": [],
"temporary_ipv6_addresses": [],
"link_local_ipv6_addresses": [],
"ipv4_addresses": [
{
"address": "192.168.22.135",
"subnet_mask": "255.255.255.0",
"status": null,
"autoconfigured": false
}
],
"default_gateways": [
"192.168.22.1"
],
"dhcp_server": "192.168.22.1",
"dhcpv6_iaid": null,
"dhcpv6_client_duid": null,
"dns_servers": [
"192.168.22.151"
],
"primary_wins_server": null,
"lease_expires": "2024-09-22T22:31:26",
"lease_obtained": "2024-09-21T22:31:26",
"netbios_over_tcpip": null,
"media_state": null,
"extras": []
}
],
"extras": []
}

View File

@ -37,6 +37,8 @@ class MyTests(unittest.TestCase):
'3/22/2021, 1:15:51 PM (Coordinated Universal Time)': {'string': '3/22/2021, 1:15:51 PM (Coordinated Universal Time)', 'format': 1705, 'naive': 1616444151, 'utc': 1616418951}, '3/22/2021, 1:15:51 PM (Coordinated Universal Time)': {'string': '3/22/2021, 1:15:51 PM (Coordinated Universal Time)', 'format': 1705, 'naive': 1616444151, 'utc': 1616418951},
# Windows english format with UTC tz (found in systeminfo cli output) # Windows english format with UTC tz (found in systeminfo cli output)
'3/22/2021, 1:15:51 PM (UTC+0000)': {'string': '3/22/2021, 1:15:51 PM (UTC+0000)', 'format': 1710, 'naive': 1616444151, 'utc': 1616418951}, '3/22/2021, 1:15:51 PM (UTC+0000)': {'string': '3/22/2021, 1:15:51 PM (UTC+0000)', 'format': 1710, 'naive': 1616444151, 'utc': 1616418951},
# Windows ipconfig cli output format
'Thursday, June 22, 2023 10:39:04 AM': {'string': 'Thursday, June 22, 2023 10:39:04 AM', 'format': 1720, 'naive': 1687455544, 'utc': None},
# Google Big Table format with no timezone: # Google Big Table format with no timezone:
'2000/01/01-01:00:00.000000': {'string': '2000/01/01-01:00:00.000000', 'format': 1750, 'naive': 946717200, 'utc': None}, '2000/01/01-01:00:00.000000': {'string': '2000/01/01-01:00:00.000000', 'format': 1750, 'naive': 946717200, 'utc': None},
# Google Big Table format with timezone: # Google Big Table format with timezone: