How to set ip address to a computer in Qt (Solved)
-
Since you are sudo'ing the command, have you made sure about the authentication ?
-
i trying to pass the password over to the terminal after the sudo'ing command.
is it possible to pass my password and authenticate? I check many links
http://stackoverflow.com/questions/9619652/qt-setting-the-ip.Is it true this cannot be done in Qt?
-
AFAIK, You will have to either run the Qt program as root or you can provide a password file to sudo eg.
@
sudo -S ifconfig eth0 192.168.100.4 < /home/user/passwd.txt
@(but beware of security risks)
-
[quote author="p3c0" date="1415858672"]AFAIK, You will have to either run the Qt program as root or you can provide a password file to sudo eg.
@
sudo -S ifconfig eth0 192.168.100.4 < /home/user/passwd.txt
@(but beware of security risks)[/quote]
Hi
Thanks it's very useful command.
i use from QProcess too
read Standard Outputs and ... -
Seeking help again. My Ubuntu terminal does open, but nothing is wrote onto it. why is it so?
@
QProcess *myProcess = new QProcess;
myProcess->start("gnome-terminal");
myProcess->waitForStarted(5000);
myProcess->write("Qt rocks");
myProcess->write("sudo -S ifconfig eth0 192.168.100.4 netmask 255.255.255.0");@
-
Seeking help again. My Ubuntu terminal does open, but nothing is wrote onto it. why is it so?
@
QProcess *myProcess = new QProcess;
myProcess->start("gnome-terminal");
myProcess->waitForStarted(5000);
myProcess->write("Qt rocks");
myProcess->write("sudo -S ifconfig eth0 192.168.100.4 netmask 255.255.255.0");@
-
You need not open a terminal for launching that process. Try following:
@
QStringList args;
args << "-c" << "sudo -S ifconfig eth0 192.168.0.21 < /home/user/passwd.txt";
pro->start("/bin/sh",args);
@But as said earlier it doesnot provide security as the password file is revealed.
Another way would be to write a script which will run ifconfig command. Call this script instead of that command. Add an entry for this script in /etc/sudoers alongwith the user that will execute this script (i.e linux user with which you run your application). There are plenty of examples on how to edit sudoers using visudo. Check them out. -
You need not open a terminal for launching that process. Try following:
@
QStringList args;
args << "-c" << "sudo -S ifconfig eth0 192.168.0.21 < /home/user/passwd.txt";
pro->start("/bin/sh",args);
@But as said earlier it doesnot provide security as the password file is revealed.
Another way would be to write a script which will run ifconfig command. Call this script instead of that command. Add an entry for this script in /etc/sudoers alongwith the user that will execute this script (i.e linux user with which you run your application). There are plenty of examples on how to edit sudoers using visudo. Check them out. -
i vi a file in /home/ubuntu/passwd.txt with my password. Debug the code. After Application finished running, i do a ifconfig in ubuntu terminal. The ip address has not been changed
@
void SetpcAddress{QProcess *myProcess = new QProcess(); QStringList args; args<<"-c"<< "sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt"; myProcess->start("/bin/sh",args);
}
int main(void)
{SetpcAddress();
}
@
-
i vi a file in /home/ubuntu/passwd.txt with my password. Debug the code. After Application finished running, i do a ifconfig in ubuntu terminal. The ip address has not been changed
@
void SetpcAddress{QProcess *myProcess = new QProcess(); QStringList args; args<<"-c"<< "sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt"; myProcess->start("/bin/sh",args);
}
int main(void)
{SetpcAddress();
}
@
-
Does that command work from outside ?
-
Does that command work from outside ?
-
It does work for me from the App and Outside
@
args<<"-c"<<
"sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt";
@There should be a space before and after < in above command.
-
It does work for me from the App and Outside
@
args<<"-c"<<
"sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt";
@There should be a space before and after < in above command.