mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-17 01:32:37 +02:00
add ranges and fix ptr
This commit is contained in:
@ -30,6 +30,7 @@ Examples:
|
|||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
import binascii
|
import binascii
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
from collections import deque
|
||||||
import jc.utils
|
import jc.utils
|
||||||
|
|
||||||
|
|
||||||
@ -101,21 +102,37 @@ def parse(
|
|||||||
network_string = str(interface.network).split('/')[0]
|
network_string = str(interface.network).split('/')[0]
|
||||||
network_cidr = str(interface.with_prefixlen).split('/')[1]
|
network_cidr = str(interface.with_prefixlen).split('/')[1]
|
||||||
network = ipaddress.ip_network(f'{network_string}/{network_cidr}')
|
network = ipaddress.ip_network(f'{network_string}/{network_cidr}')
|
||||||
|
bare_ip_string = str(interface.ip)
|
||||||
|
bare_ip = ipaddress.ip_address(bare_ip_string)
|
||||||
|
ip_ptr = bare_ip.reverse_pointer
|
||||||
|
|
||||||
|
first_host = next(network.hosts())
|
||||||
|
|
||||||
|
# hack to speed up iterating through large ipv6 subnets
|
||||||
|
# only do last_host for masks >= /16 (ipv4) or >= /120 (ipv6)
|
||||||
|
last_host = None
|
||||||
|
|
||||||
|
if any((
|
||||||
|
int(interface.version) == 4 and int(network_cidr) >= 16,
|
||||||
|
int(interface.version) == 6 and int(network_cidr) >= 120,
|
||||||
|
)):
|
||||||
|
dd = deque(network.hosts(), maxlen=1)
|
||||||
|
last_host = str(dd.pop())
|
||||||
|
|
||||||
raw_output = {
|
raw_output = {
|
||||||
'version': int(interface.version),
|
'version': int(interface.version),
|
||||||
'max_prefix_length': int(interface.max_prefixlen),
|
'max_prefix_length': int(interface.max_prefixlen),
|
||||||
'ip': str(interface.ip),
|
'ip': bare_ip_string,
|
||||||
'ip_compressed': str(interface.compressed),
|
'ip_compressed': str(interface.compressed),
|
||||||
'ip_exploded': str(interface.exploded),
|
'ip_exploded': str(interface.exploded),
|
||||||
'dns_ptr': str(interface.reverse_pointer),
|
'dns_ptr': ip_ptr,
|
||||||
'network': network_string,
|
'network': network_string,
|
||||||
'broadcast': str(network.broadcast_address),
|
'broadcast': str(network.broadcast_address),
|
||||||
'hostmask': str(interface.with_hostmask).split('/')[1],
|
'hostmask': str(interface.with_hostmask).split('/')[1],
|
||||||
'netmask': str(interface.with_netmask).split('/')[1],
|
'netmask': str(interface.with_netmask).split('/')[1],
|
||||||
'cidr_netmask': network_cidr,
|
'cidr_netmask': int(network_cidr),
|
||||||
'first_host': 1, # implement
|
'first_host': str(first_host),
|
||||||
'last_host': 2, # implement
|
'last_host': last_host, # None if netmask is too small
|
||||||
'is_multicast': interface.is_multicast,
|
'is_multicast': interface.is_multicast,
|
||||||
'is_private': interface.is_private,
|
'is_private': interface.is_private,
|
||||||
'is_global': interface.is_global,
|
'is_global': interface.is_global,
|
||||||
@ -124,7 +141,7 @@ def parse(
|
|||||||
'is_reserved': interface.is_reserved,
|
'is_reserved': interface.is_reserved,
|
||||||
'is_unspecified': interface.is_unspecified,
|
'is_unspecified': interface.is_unspecified,
|
||||||
'hex': {
|
'hex': {
|
||||||
'ip': _b2a(interface.packed),
|
'ip': _b2a(bare_ip.packed),
|
||||||
'network': 1, # implement
|
'network': 1, # implement
|
||||||
'broadcast': 2, # implement
|
'broadcast': 2, # implement
|
||||||
'hostmask': 3, # implement
|
'hostmask': 3, # implement
|
||||||
|
81
tests/fixtures/generic/lsusb-device-qualifier.out
vendored
Normal file
81
tests/fixtures/generic/lsusb-device-qualifier.out
vendored
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
|
||||||
|
Bus 002 Device 002: ID 8087:8000 Intel Corp. Integrated Rate Matching Hub
|
||||||
|
Device Descriptor:
|
||||||
|
bLength 18
|
||||||
|
bDescriptorType 1
|
||||||
|
bcdUSB 2.00
|
||||||
|
bDeviceClass 9 Hub
|
||||||
|
bDeviceSubClass 0
|
||||||
|
bDeviceProtocol 1 Single TT
|
||||||
|
bMaxPacketSize0 64
|
||||||
|
idVendor 0x8087 Intel Corp.
|
||||||
|
idProduct 0x8000 Integrated Rate Matching Hub
|
||||||
|
bcdDevice 0.04
|
||||||
|
iManufacturer 0
|
||||||
|
iProduct 0
|
||||||
|
iSerial 0
|
||||||
|
bNumConfigurations 1
|
||||||
|
Configuration Descriptor:
|
||||||
|
bLength 9
|
||||||
|
bDescriptorType 2
|
||||||
|
wTotalLength 0x0019
|
||||||
|
bNumInterfaces 1
|
||||||
|
bConfigurationValue 1
|
||||||
|
iConfiguration 0
|
||||||
|
bmAttributes 0xe0
|
||||||
|
Self Powered
|
||||||
|
Remote Wakeup
|
||||||
|
MaxPower 0mA
|
||||||
|
Interface Descriptor:
|
||||||
|
bLength 9
|
||||||
|
bDescriptorType 4
|
||||||
|
bInterfaceNumber 0
|
||||||
|
bAlternateSetting 0
|
||||||
|
bNumEndpoints 1
|
||||||
|
bInterfaceClass 9 Hub
|
||||||
|
bInterfaceSubClass 0
|
||||||
|
bInterfaceProtocol 0 Full speed (or root) hub
|
||||||
|
iInterface 0
|
||||||
|
Endpoint Descriptor:
|
||||||
|
bLength 7
|
||||||
|
bDescriptorType 5
|
||||||
|
bEndpointAddress 0x81 EP 1 IN
|
||||||
|
bmAttributes 3
|
||||||
|
Transfer Type Interrupt
|
||||||
|
Synch Type None
|
||||||
|
Usage Type Data
|
||||||
|
wMaxPacketSize 0x0002 1x 2 bytes
|
||||||
|
bInterval 12
|
||||||
|
Hub Descriptor:
|
||||||
|
bLength 11
|
||||||
|
bDescriptorType 41
|
||||||
|
nNbrPorts 8
|
||||||
|
wHubCharacteristic 0x0009
|
||||||
|
Per-port power switching
|
||||||
|
Per-port overcurrent protection
|
||||||
|
TT think time 8 FS bits
|
||||||
|
bPwrOn2PwrGood 0 * 2 milli seconds
|
||||||
|
bHubContrCurrent 0 milli Ampere
|
||||||
|
DeviceRemovable 0x00 0x00
|
||||||
|
PortPwrCtrlMask 0xff 0xff
|
||||||
|
Hub Port Status:
|
||||||
|
Port 1: 0000.0100 power
|
||||||
|
Port 2: 0000.0100 power
|
||||||
|
Port 3: 0000.0100 power
|
||||||
|
Port 4: 0000.0100 power
|
||||||
|
Port 5: 0000.0100 power
|
||||||
|
Port 6: 0000.0100 power
|
||||||
|
Port 7: 0000.0100 power
|
||||||
|
Port 8: 0000.0100 power
|
||||||
|
Device Qualifier (for other device speed):
|
||||||
|
bLength 10
|
||||||
|
bDescriptorType 6
|
||||||
|
bcdUSB 2.00
|
||||||
|
bDeviceClass 9 Hub
|
||||||
|
bDeviceSubClass 0
|
||||||
|
bDeviceProtocol 0 Full speed (or root) hub
|
||||||
|
bMaxPacketSize0 64
|
||||||
|
bNumConfigurations 1
|
||||||
|
Device Status: 0x0001
|
||||||
|
Self Powered
|
||||||
|
|
Reference in New Issue
Block a user