Results 1 to 8 of 8

Thread: filter QNetworkInterface::hardwareAddress()

  1. #1
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default filter QNetworkInterface::hardwareAddress()

    The following code

    Qt Code:
    1. foreach (const QNetworkInterface &ni, QNetworkInterface::allInterfaces()) {
    2. if (!(ni.flags() & ni.IsLoopBack)){
    3. macName = ni.hardwareAddress(); // lets match & get our information for this device
    4. qDebug() << macName;
    To copy to clipboard, switch view to plain text mode 

    outputs

    Qt Code:
    1. "00:1C:DF:93:1D:5D"
    2. "00:1C:DF:93:1D:5D"
    3. "00:23:AE:A8:26:FC" // this one being Local Area Connection
    4. "00:50:56:C0:00:01"
    5. "00:50:56:C0:00:08"
    6. "3E:9B:20:52:41:53"
    7. "3E:9B:20:52:41:53"
    8. "00:23:AE:A8:26:FC"
    9. "00:23:AE:A8:26:FC"
    10. "3E:9B:20:52:41:53"
    11. "3E:9B:20:52:41:53"
    12. "3E:9B:20:52:41:53"
    13. "3E:9B:20:52:41:53"
    14. "20:41:53:59:4E:FF"
    15. "00:00:00:00:00:00:00:00"
    16. "00:00:00:00:00:00:00:E0"
    17. "00:00:00:00:00:00:00:E0"
    18. "00:00:00:00:00:00:00:E0"
    19. "00:00:00:00:00:00:00:E0"
    20. "00:00:00:00:00:00:00:E0"
    To copy to clipboard, switch view to plain text mode 

    how can i filter threw the hardware addresses where QNetworkInterface::humanReadableName = local area connection and spit that one out only ?

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: filter QNetworkInterface::hardwareAddress()

    Unless I'm not getting something it sounds pretty straight forward.

    Just loop through the interfaces comparing humanReadableName() to your string and if you find a match return hardwareAddress().

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: filter QNetworkInterface::hardwareAddress()

    If you don't want all the addresses why go looking for them? QNetworkInterface::interfaceFromName() is the direct method.

  4. #4
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: filter QNetworkInterface::hardwareAddress()

    Qt Code:
    1. QString string = "Local Area Connection";
    2. qDebug() << ni.interfaceFromName(string);
    To copy to clipboard, switch view to plain text mode 

    shows

    Qt Code:
    1. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    2.  
    3. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    4.  
    5. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    6.  
    7. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    8.  
    9. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    10.  
    11. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    12.  
    13. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    14.  
    15. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    16.  
    17. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    18.  
    19. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    20.  
    21. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    22.  
    23. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    24.  
    25. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    26.  
    27. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    28.  
    29. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    30.  
    31. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    32.  
    33. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    34.  
    35. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    36.  
    37. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    38.  
    39. QNetworkInterface(name = "", hardware address = "", flags = , entries = () )
    To copy to clipboard, switch view to plain text mode 

    So now you can see my confusion

  5. #5
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: filter QNetworkInterface::hardwareAddress()

    interfaceFromName() expects interface name returned by QNetworkInterface::name() (ie "{D6637618-7E2B-466B-B02B-C35A1FA9118F}") not QNetworkInterface::humanReadableName().

    So, if you want to find interface by human readable name you have to loop through the interfaces and find it yourself.

    In the end it's only few lines of code:
    Qt Code:
    1. QList< QNetworkInterface > it = QNetworkInterface::allInterfaces();
    2. for( int i = 0; i < it.size(); ++i )
    3. {
    4. if( it.at( i ).humanReadableName() == "Local Area Connection" )
    5. {
    6. qDebug() << it.at( i ).hardwareAddress();
    7. break;
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to Spitfire for this useful post:

    prophet0 (12th April 2012)

  7. #6
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: filter QNetworkInterface::hardwareAddress()

    That works perfectly thanks very much

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: filter QNetworkInterface::hardwareAddress()

    Quote Originally Posted by Spitfire View Post
    interfaceFromName() expects interface name returned by QNetworkInterface::name() (ie "{D6637618-7E2B-466B-B02B-C35A1FA9118F}") not QNetworkInterface::humanReadableName().
    Is that some Windows perversion? QNetworkInterface::interfaceFromName() works perfectly fine with "eth0", i.e. the same as the humanReadableName(), on Linux.

  9. #8
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: filter QNetworkInterface::hardwareAddress()

    On linux both are the same but Microsoft invented 'better' way, obviously

Similar Threads

  1. QNetworkInterface::allAddresses() crash
    By ^NyAw^ in forum Qt Programming
    Replies: 12
    Last Post: 15th October 2014, 03:06
  2. hardwareAddress(es)
    By uygar in forum Qt Programming
    Replies: 13
    Last Post: 17th June 2009, 10:42
  3. QNetworkInterface get IP
    By pdoria in forum Newbie
    Replies: 2
    Last Post: 3rd January 2008, 08:48
  4. problem w/qnetworkinterface.h
    By ber_44 in forum Installation and Deployment
    Replies: 2
    Last Post: 13th April 2007, 11:38
  5. Discovery ifdown/ifup on all OS; by QNetworkInterface
    By patrik08 in forum Qt Programming
    Replies: 0
    Last Post: 3rd April 2007, 12:27

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.