PDA

View Full Version : QNetworkAddressEntry new ip set BUG && netsh



patrik08
5th April 2007, 08:49
To set a new ip or save location on my window OS notebook i know only one primityve way....



### backup ip config
netsh -c interface dump>c:\today.txt
### put new ip from other location ... to today.txt
### load ip config
netsh -f c:\today.txt


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/qnetworkaddressentry.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 ....



void Load_Position( int netpos )
{
const QString OsInterfacesName = net->itemData(netpos).toString();
if (OsInterfacesName.size() < 1) {
return;
}
QNetworkInterface hop = QNetworkInterface::interfaceFromName(OsInterfacesN ame);
int ddi = hop.flags();
qDebug() << "hop.flags() >>> " << ddi;
QList<QNetworkAddressEntry> allhop = hop.addressEntries();

foreach(QNetworkAddressEntry eth, allhop) {
if (allhop.size() == 1 ) {
/* window os on name --- linux eth0:1 eth0:1 ecc... virtual ip */
actual = eth;
}
wbroad->setText(eth.broadcast().toString());
wmask->setText(eth.netmask().toString());
wip->setText(eth.ip().toString());
}
if ( wip->text().size() > 0 || wmask->text().size() > 0 || hop.isValid() ) {
/* have it */
qDebug() << " valid config && running ";
/* enable button to chance ip */
wset->setEnabled(true);
} else {
wset->setEnabled(false);
}

}



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

the full apps on attach zip

wysota
5th April 2007, 12:08
Is there a question here somewhere? Where is the bug you mentioned in the subject?

patrik08
5th April 2007, 12:42
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-interest/2006-10/thread00569-0.html
http://lists.trolltech.com/qt-interest/2006-07/thread00155-0.html

the QT class not make job!:(


put other IP not work!!!



void SetNew()
{
const QString xip = wip->text();
const QString xmask = wmask->text();
const QString xboad = wbroad->text();

/* actual last QNetworkAddressEntry */


/////if (actual) {
actual.setIp(QHostAddress(xip));
actual.setNetmask(QHostAddress(xmask));
actual.setBroadcast(QHostAddress(xboad));


qDebug() << " ok now check " << actual.ip().toString();

QString status;
QProcess process;
#if defined Q_WS_WIN
process.setReadChannelMode(QProcess::MergedChannel s);
process.start("ipconfig" , QStringList() << "/all");
if (!process.waitForFinished()) {
status = process.errorString();
} else {
status = process.readAll();
}
#endif
#if defined Q_WS_X11
/* sudo ifconfig */
qDebug() << "sudo ifconfig to check!!! ";
status = "Check ip new...";
#endif
QMessageBox::information(this, tr("Config result"),
status,
QMessageBox::Close);

///// }

}

wysota
5th April 2007, 13:27
Hmm... seems to work fine:

#include <QtDebug>
#include <QNetworkAddressEntry>


int main(){
QNetworkAddressEntry entry;
qDebug() << entry.ip().toString();
QHostAddress newaddr("1.2.3.4");
entry.setIp(newaddr);
qDebug() << entry.ip().toString();
return 0;
}

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.

patrik08
5th April 2007, 13:40
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?

wysota
5th April 2007, 14:15
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:

void QNetworkAddressEntry::setIp(const QHostAddress &newIp)
{
d->address = newIp;
}

patrik08
5th April 2007, 16:03
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 :rolleyes: )
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? ...

wysota
5th April 2007, 16:26
I not see the sense ... to setter an ip ... only for fun ( i like a setter to my age :rolleyes: )
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.