Results 1 to 3 of 3

Thread: Parsing linux command 'iwlist' with Qt

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Parsing linux command 'iwlist' with Qt

    I am working on some network info application, I've tried Qt Bearer Management, however, I do no get all needed info. So, I've moved to QProcess and through it I inwoke linux command iwlist scan. Then I read all stdout info and it works perfectly. Here is my example `iwlist scan` stdout:
    Qt Code:
    1. lo Interface doesn't support scanning.
    2.  
    3. wlan0 Scan completed :
    4. Cell 01 - Address: 64:6E:EA:22:21:D4
    5. Channel:1
    6. Frequency:2.412 GHz (Channel 1)
    7. Quality=38/70 Signal level=-72 dBm
    8. Encryption key:on
    9. ESSID:"heer"
    10. Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
    11. 24 Mb/s; 36 Mb/s; 54 Mb/s
    12. Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s
    13. Mode:Master
    14. Extra:tsf=000001d13478be74
    15. Extra: Last beacon: 11840ms ago
    16. IE: Unknown: 000468656572
    17. IE: Unknown: 010882848B962430486C
    18. IE: Unknown: 030101
    19. IE: Unknown: 2A0100
    20. IE: Unknown: 32040C121860
    21. IE: IEEE 802.11i/WPA2 Version 1
    22. Group Cipher : TKIP
    23. Pairwise Ciphers (2) : CCMP TKIP
    24. Authentication Suites (1) : PSK
    25. IE: Unknown: 0B0501004B0000
    26. IE: Unknown: 46053208010000
    27. IE: Unknown: 2D1ABC081BFFFF000000000000000000000000000000000000000000
    28. IE: Unknown: 3D1601080400000000000000000000000000000000000000
    29. IE: Unknown: 7F080400080000000040
    30. IE: Unknown: DD090010180201000C0000
    31. IE: WPA Version 1
    32. Group Cipher : TKIP
    33. Pairwise Ciphers (2) : CCMP TKIP
    34. Authentication Suites (1) : PSK
    35. IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00
    36. Cell 02 - Address: 00:23:CD:1D:BB:5C
    37. Channel:4
    38. Frequency:2.427 GHz (Channel 4)
    39. Quality=31/70 Signal level=-79 dBm
    40. Encryption key:on
    41. ESSID:"TP-LINK_1DBB5C"
    42. Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
    43. 9 Mb/s; 12 Mb/s; 18 Mb/s
    44. Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
    45. Mode:Master
    46. Extra:tsf=000000235998fd80
    47. Extra: Last beacon: 12372ms ago
    48. IE: Unknown: 000E54502D4C494E4B5F314442423543
    49. IE: Unknown: 010882848B960C121824
    50. IE: Unknown: 030104
    51. IE: Unknown: 050400010000
    52. IE: Unknown: 2A0100
    53. IE: IEEE 802.11i/WPA2 Version 1
    54. Group Cipher : CCMP
    55. Pairwise Ciphers (1) : CCMP
    56. Authentication Suites (1) : PSK
    57. IE: WPA Version 1
    58. Group Cipher : CCMP
    59. Pairwise Ciphers (1) : CCMP
    60. Authentication Suites (1) : PSK
    61. IE: Unknown: 32043048606C
    62. IE: Unknown: DD180050F2020101860003A4000027A4000042435E0062322F00
    63. IE: Unknown: DD1E00904C334E111BFF00000000000000000000000000000000000000000000
    64. IE: Unknown: 2D1A4E111BFF00000000000000000000000000000000000000000000
    65. IE: Unknown: DD1A00904C34040D0800000000000000000000000000000000000000
    66. IE: Unknown: 3D16040D0800000000000000000000000000000000000000
    67. IE: Unknown: DD0900037F01010000FF7F
    68. IE: Unknown: DD0A00037F04010000004000
    69. Cell 03 - Address: 14:CC:20:F6:80:0A
    70. Channel:11
    71. Frequency:2.462 GHz (Channel 11)
    72. Quality=24/70 Signal level=-86 dBm
    73. Encryption key:on
    74. ESSID:"P_wifi"
    75. Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
    76. 9 Mb/s; 12 Mb/s; 18 Mb/s
    77. Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
    78. Mode:Master
    79. Extra:tsf=0000000e8cd44180
    80. Extra: Last beacon: 11964ms ago
    81. IE: Unknown: 0006505F77696669
    82. IE: Unknown: 010882848B960C121824
    83. IE: Unknown: 03010B
    84. IE: Unknown: 050400010000
    85. IE: Unknown: 0706534920010D14
    86. IE: Unknown: 2A0100
    87. IE: IEEE 802.11i/WPA2 Version 1
    88. Group Cipher : CCMP
    89. Pairwise Ciphers (1) : CCMP
    90. Authentication Suites (1) : PSK
    91. IE: Unknown: 32043048606C
    92. IE: Unknown: 2D1A6E1103FF00000000000000000000000000000000000000000000
    93. IE: Unknown: 3D160B0F0600000000000000000000000000000000000000
    94. IE: WPA Version 1
    95. Group Cipher : CCMP
    96. Pairwise Ciphers (1) : CCMP
    97. Authentication Suites (1) : PSK
    98. IE: Unknown: DD180050F2020101030003A4000027A4000042435E0062322F00
    99. IE: Unknown: DD1E00904C336E1103FF00000000000000000000000000000000000000000000
    100. IE: Unknown: DD1A00904C340B0F0600000000000000000000000000000000000000
    101. IE: Unknown: DD0900037F01010000FF7F
    102. IE: Unknown: DD3F0050F204104A0001101044000102104700100000000000001000000014CC20F68010103C000101104900140024E26002000101600000020001600100020001
    103.  
    104. eth0 Interface doesn't support scanning.
    To copy to clipboard, switch view to plain text mode 
    Current, I have three network interfaces:
    1. lo
    2. wlan0
    3. eth0

    Now, from this list I would like to create QMap with key interfaceName(lo, wlan, eth0, ...) and value of QPair with key - parameter name (SSID, channel, frequency, quality, signal level, encryption type, mac address) and as value parameter value itself. If some network interface is NOT WiFi/BroadBand, it can be ignored - not added to QMap at all. How do I parse this output to place fetched info into QMap(QString, QList<QPair<QString, QString>>)? I am working on Qt Desktop Opensource 5.7 for Linux 64bit.
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Parsing linux command 'iwlist' with Qt

    Read the output line by line. When you detect an interface name (e.g. by indentation) all following lines up to the next interface name will be containing info about that interface. Indentations mark the structure (more indented lines are submaps of the previous line). Split the lines by first colon and you'll have keys and values. If a line doesn't have a colon, append it to the value of the previous key.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    MarkoSan (15th September 2016)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Parsing linux command 'iwlist' with Qt

    Parsing text data should be the last resort.

    If you can I would suggest to research which APIs the tool is using to get the data and try to call those yourself.

    There could also be D-Bus API, e.g. in systemd or NetworkManager, that allows to query for some of that.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    MarkoSan (15th September 2016)

Similar Threads

  1. Replies: 2
    Last Post: 7th April 2015, 09:18
  2. To pass a value as response to linux command using QT
    By chillin in forum Qt Programming
    Replies: 7
    Last Post: 3rd March 2014, 15:42
  3. Executing linux command as root
    By stefan in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2011, 16:07
  4. make[2]:arm-linux-g++:Command not found.(Greenphone SDK)
    By rishiraj in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 17th April 2009, 14:57
  5. Linux/Bash: Run a command as another user
    By sunil.thaha in forum General Discussion
    Replies: 1
    Last Post: 5th December 2006, 10:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.