Results 1 to 8 of 8

Thread: QNetworkAddressEntry new ip set BUG && netsh

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QNetworkAddressEntry new ip set BUG && netsh

    To set a new ip or save location on my window OS notebook i know only one primityve way....

    Qt Code:
    1. ### backup ip config
    2. netsh -c interface dump>c:\today.txt
    3. ### put new ip from other location ... to today.txt
    4. ### load ip config
    5. netsh -f c:\today.txt
    To copy to clipboard, switch view to plain text mode 

    one the same pc on xubuntu i put a new name location .. and each place wo i go ... i only switch a combobox ... and the new config is running .... magic ... :-) like Mac OS X

    on QNetworkAddressEntry
    http://doc.trolltech.com/qtopia4.2/q...ressentry.html

    i found a ip handler ... to chance ip but not work so if describe on doc... why??

    why Only win Os make software expensive! and trouble?

    i make a combobox from each network card.... and i suppose to chanche ....
    Qt Code:
    1. void Load_Position( int netpos )
    2. {
    3. const QString OsInterfacesName = net->itemData(netpos).toString();
    4. if (OsInterfacesName.size() < 1) {
    5. return;
    6. }
    7. QNetworkInterface hop = QNetworkInterface::interfaceFromName(OsInterfacesName);
    8. int ddi = hop.flags();
    9. qDebug() << "hop.flags() >>> " << ddi;
    10. QList<QNetworkAddressEntry> allhop = hop.addressEntries();
    11.  
    12. foreach(QNetworkAddressEntry eth, allhop) {
    13. if (allhop.size() == 1 ) {
    14. /* window os on name --- linux eth0:1 eth0:1 ecc... virtual ip */
    15. actual = eth;
    16. }
    17. wbroad->setText(eth.broadcast().toString());
    18. wmask->setText(eth.netmask().toString());
    19. wip->setText(eth.ip().toString());
    20. }
    21. if ( wip->text().size() > 0 || wmask->text().size() > 0 || hop.isValid() ) {
    22. /* have it */
    23. qDebug() << " valid config && running ";
    24. /* enable button to chance ip */
    25. wset->setEnabled(true);
    26. } else {
    27. wset->setEnabled(false);
    28. }
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 

    or is the better way edit netsh result file and resend it... ??

    the full apps on attach zip
    Attached Files Attached Files

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

    Default Re: QNetworkAddressEntry new ip set BUG && netsh

    Is there a question here somewhere? Where is the bug you mentioned in the subject?

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAddressEntry new ip set BUG && netsh

    Quote Originally Posted by wysota View Post
    Is there a question here somewhere? Where is the bug you mentioned in the subject?
    IP not chance ... bug not found on Trolltech ...
    same problem as :
    http://lists.trolltech.com/qt-intere...ad00569-0.html
    http://lists.trolltech.com/qt-intere...ad00155-0.html

    the QT class not make job!


    put other IP not work!!!
    Qt Code:
    1. void SetNew()
    2. {
    3. const QString xip = wip->text();
    4. const QString xmask = wmask->text();
    5. const QString xboad = wbroad->text();
    6.  
    7. /* actual last QNetworkAddressEntry */
    8.  
    9.  
    10. /////if (actual) {
    11. actual.setIp(QHostAddress(xip));
    12. actual.setNetmask(QHostAddress(xmask));
    13. actual.setBroadcast(QHostAddress(xboad));
    14.  
    15.  
    16. qDebug() << " ok now check " << actual.ip().toString();
    17.  
    18. QString status;
    19. QProcess process;
    20. #if defined Q_WS_WIN
    21. process.setReadChannelMode(QProcess::MergedChannels);
    22. process.start("ipconfig" , QStringList() << "/all");
    23. if (!process.waitForFinished()) {
    24. status = process.errorString();
    25. } else {
    26. status = process.readAll();
    27. }
    28. #endif
    29. #if defined Q_WS_X11
    30. /* sudo ifconfig */
    31. qDebug() << "sudo ifconfig to check!!! ";
    32. status = "Check ip new...";
    33. #endif
    34. QMessageBox::information(this, tr("Config result"),
    35. status,
    36. QMessageBox::Close);
    37.  
    38. ///// }
    39.  
    40. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QNetworkAddressEntry new ip set BUG && netsh

    Hmm... seems to work fine:
    Qt Code:
    1. #include <QtDebug>
    2. #include <QNetworkAddressEntry>
    3.  
    4.  
    5. int main(){
    6. qDebug() << entry.ip().toString();
    7. QHostAddress newaddr("1.2.3.4");
    8. entry.setIp(newaddr);
    9. qDebug() << entry.ip().toString();
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

    Result:
    $ ./net
    ""
    "1.2.3.4"

    If you think the problem is that setIp() doesn't change the actual address of a network interface, it is because it is not meant to do so. The docs clearly say, that setIp() sets the ip field of the QNetworkAddressEntry object. Besides, it is logical that you can't change NIC address from your application as it would require superuser priviledges.

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAddressEntry new ip set BUG && netsh

    Quote Originally Posted by wysota View Post
    Hmm... seems to work fine:
    [code]#include <QtDebug>
    script ....

    Result:
    $ ./net
    ""
    "1.2.3.4"

    If you think the problem is that setIp() doesn't change the actual address of a network interface, it is because it is not meant to do so. The docs clearly say, that setIp() sets the ip field of the QNetworkAddressEntry object. Besides, it is logical that you can't change NIC address from your application as it would require superuser priviledges.
    if You run this script from linux root not / ipconfig have other ip....
    same administrator on Window / ipconfig /all not display the new ip....

    only class have an other ip nummer!.. or is this indended as qtcpsocket to display on remote server a Anonimous IP? and hidden the real IP?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAddressEntry new ip set BUG && netsh

    As I said... setIp() is a setter method for the "ip" field of QNetworkAddressEntry, not a way to change the address of an actual interface.

    It's implemented like this:
    Qt Code:
    1. void QNetworkAddressEntry::setIp(const QHostAddress &newIp)
    2. {
    3. d->address = newIp;
    4. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAddressEntry new ip set BUG && netsh

    Quote Originally Posted by wysota View Post
    As I said... setIp() is a setter method for the "ip" field of QNetworkAddressEntry, not a way to change the address of an actual interface.
    I not see the sense ... to setter an ip ... only for fun ( i like a setter to my age )
    anyway on this case the unique method to chance real an ip adress is QRegExp ip on
    netsh -c interface dump>c:\today.txt edit and resend on qprocess on window?
    or you see other not primitive way? on window? ...

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAddressEntry new ip set BUG && netsh

    Quote Originally Posted by patrik08 View Post
    I not see the sense ... to setter an ip ... only for fun ( i like a setter to my age )
    Treat this class as a container for a set of data that describes a network address - a triple of ip address, netmask and broadcast address - nothing more, nothing less.

    anyway on this case the unique method to chance real an ip adress is QRegExp ip on
    netsh -c interface dump>c:\today.txt edit and resend on qprocess on window?
    or you see other not primitive way? on window? ...
    No matter what you do, you'll need superuser priviledges - no matter if you run your code on modern Windows or Unix. If your account doesn't have priviledges to change the network address, you won't be able to do it without any helper applications, like "sudo" or "su" on Unix. If you have a user with administrator priviledges it's only because you violate one of the rules of having a secure working environment. Don't rely on this to be always true.

Similar Threads

  1. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43

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.