Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to set ip address to a computer in Qt (Solved)
QtWS25 Last Chance

How to set ip address to a computer in Qt (Solved)

Scheduled Pinned Locked Moved Mobile and Embedded
32 Posts 4 Posters 12.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • p3c0P Offline
    p3c0P Offline
    p3c0
    Moderators
    wrote on last edited by
    #8

    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)

    157

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jafarabadi.qt
      wrote on last edited by
      #9

      [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 ...

      1 Reply Last reply
      0
      • H Offline
        H Offline
        houmingc
        wrote on last edited by
        #10

        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");

        @

        1 Reply Last reply
        0
        • H Offline
          H Offline
          houmingc
          wrote on last edited by
          #11

          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");

          @

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #12

            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.

            157

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #13

              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.

              157

              1 Reply Last reply
              0
              • H Offline
                H Offline
                houmingc
                wrote on last edited by
                #14

                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();    
                

                }

                @

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  houmingc
                  wrote on last edited by
                  #15

                  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();    
                  

                  }

                  @

                  1 Reply Last reply
                  0
                  • p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #16

                    Does that command work from outside ?

                    157

                    1 Reply Last reply
                    0
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #17

                      Does that command work from outside ?

                      157

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        houmingc
                        wrote on last edited by
                        #18

                        cat passwd.txt return my password correct

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          houmingc
                          wrote on last edited by
                          #19

                          cat passwd.txt return my password correct

                          1 Reply Last reply
                          0
                          • H Offline
                            H Offline
                            houmingc
                            wrote on last edited by
                            #20

                            it works when i do a sudo su
                            it doesn't work without permission, what should i do next?

                            1 Reply Last reply
                            0
                            • H Offline
                              H Offline
                              houmingc
                              wrote on last edited by
                              #21

                              it works when i do a sudo su
                              it doesn't work without permission, what should i do next?

                              1 Reply Last reply
                              0
                              • p3c0P Offline
                                p3c0P Offline
                                p3c0
                                Moderators
                                wrote on last edited by
                                #22

                                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.

                                157

                                1 Reply Last reply
                                0
                                • p3c0P Offline
                                  p3c0P Offline
                                  p3c0
                                  Moderators
                                  wrote on last edited by
                                  #23

                                  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.

                                  157

                                  1 Reply Last reply
                                  0
                                  • H Offline
                                    H Offline
                                    houmingc
                                    wrote on last edited by
                                    #24

                                    under /opt
                                    cat >password.txt 'Key in my password'
                                    cat password 'Check my password'

                                    its work, thanks alot :>>

                                    1 Reply Last reply
                                    0
                                    • H Offline
                                      H Offline
                                      houmingc
                                      wrote on last edited by
                                      #25

                                      under /opt
                                      cat >password.txt 'Key in my password'
                                      cat password 'Check my password'

                                      its work, thanks alot :>>

                                      1 Reply Last reply
                                      0
                                      • p3c0P Offline
                                        p3c0P Offline
                                        p3c0
                                        Moderators
                                        wrote on last edited by
                                        #26

                                        Well then get the errors using readyReadStandardError() signal if any.

                                        157

                                        1 Reply Last reply
                                        0
                                        • p3c0P Offline
                                          p3c0P Offline
                                          p3c0
                                          Moderators
                                          wrote on last edited by
                                          #27

                                          Well then get the errors using readyReadStandardError() signal if any.

                                          157

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved