How to set ip address to a computer in Qt (Solved)
-
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)
-
wrote on 14 Nov 2014, 06:15 last edited by
[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 ... -
wrote on 27 Jan 2015, 08:29 last edited by
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");@
-
wrote on 27 Jan 2015, 08:29 last edited by
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. -
wrote on 27 Jan 2015, 09:26 last edited by
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();
}
@
-
wrote on 27 Jan 2015, 09:26 last edited by
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 ?
-
wrote on 27 Jan 2015, 09:30 last edited by
cat passwd.txt return my password correct
-
wrote on 27 Jan 2015, 09:30 last edited by
cat passwd.txt return my password correct
-
wrote on 27 Jan 2015, 09:34 last edited by
it works when i do a sudo su
it doesn't work without permission, what should i do next? -
wrote on 27 Jan 2015, 09:34 last edited by
it works when i do a sudo su
it doesn't work without permission, what should i do next? -
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.
-
wrote on 27 Jan 2015, 09:41 last edited by
under /opt
cat >password.txt 'Key in my password'
cat password 'Check my password'its work, thanks alot :>>
-
wrote on 27 Jan 2015, 09:41 last edited by
under /opt
cat >password.txt 'Key in my password'
cat password 'Check my password'its work, thanks alot :>>
-
Well then get the errors using readyReadStandardError() signal if any.
-
Well then get the errors using readyReadStandardError() signal if any.