Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnamed/non-netdev interface breaks parsing #1

Open
guysoft opened this issue Aug 15, 2022 · 1 comment
Open

Unnamed/non-netdev interface breaks parsing #1

guysoft opened this issue Aug 15, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@guysoft
Copy link

guysoft commented Aug 15, 2022

Hey, when I run

iw dev | python3 -m apparse iw device

I get:

Error parsing data: ValueError: Missing header

The otuput of iw dev is this:

phy#0
        Unnamed/non-netdev interface
                wdev 0x9
                addr 60:a5:e2:59:de:74
                type P2P-device
                txpower 0.00 dBm
        Interface wlp0s20f3
                ifindex 4
                wdev 0x1
                addr 60:a5:e2:49:de:73
                ssid SSID
                type managed
                channel 48 (5240 MHz), width: 20 MHz, center1: 5240 MHz
                txpower 22.00 dBm
                multicast TXQ:
                        qsz-byt qsz-pkt flows   drops   marks   overlmt hashcol tx-bytes        tx-packets
                        0       0       0       0       0       0       0       0               0

It seems Unnamed/non-netdev interface breaks the parsing, if I send to to the parse a file with those lines removed then the iw dev output gets parsed fine.

I tried searching using the mac address 60:a5:e2:59:de:74 in my ip a output but can't find a device that has it, so I am not sure where its coming from.

Also thanks for sharing this parser ❤️

@alexitx
Copy link
Owner

alexitx commented Aug 16, 2022

Thanks for reporting this. I don't have such unnamed device, so the parser doesn't handle it.

The thing is we're currently expecting Interface <name> at the start of each block and the name is used as a dictionary key. Since the Unnamed/non-netdev device still contains a MAC address, that could be used as a key instead, but I'm not sure if multiple devices can have the same MAC or return something like 00:00:00:00:00:00 when it's unknown.

The logic for handling the header in iw_device_parser.py#L37 could be changed to generate a list of dicts containing unknown or duplicate devices, or the unknown devices could be skipped entirely.

I'll take another look at the source of iw to see which values are always present and will see what I can do.

@alexitx alexitx self-assigned this Sep 27, 2022
@alexitx alexitx added the bug Something isn't working label Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants