Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can we do IP scanning using QT
Forum Updated to NodeBB v4.3 + New Features

Can we do IP scanning using QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
30 Posts 6 Posters 6.2k Views 1 Watching
  • 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.
  • jsulmJ jsulm

    @ManiRon Pass an URL to connectToHost instead of IP

    ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on last edited by ManiRon
    #16

    @jsulm said in Can we do IP scanning using QT:

    connectToHost

    I passed an URL but the client is not connecting to the server,

    client side :

    QTcpSocket *tcpSocket;
    tcpSocket->connectToHost("www.test.com", 6547);
    

    server side :

     QTcpServer *tcpServer;
     tcpServer->listen(QHostAddress::Any, 6547)
    
    C jsulmJ 2 Replies Last reply
    0
    • ManiRonM ManiRon

      @jsulm said in Can we do IP scanning using QT:

      connectToHost

      I passed an URL but the client is not connecting to the server,

      client side :

      QTcpSocket *tcpSocket;
      tcpSocket->connectToHost("www.test.com", 6547);
      

      server side :

       QTcpServer *tcpServer;
       tcpServer->listen(QHostAddress::Any, 6547)
      
      C Offline
      C Offline
      closx
      wrote on last edited by closx
      #17

      @ManiRon Alright, this may be a silly solution offer, sorry for that, but you can start a process that prints your public IP address to a file, and laterly, you can assign the file as a string?

      QProcess process;
      process.start("curl ifconfig.me > ipaddress");
      //Saves the public IP address as the file "ipaddress"
      //You may delete the file with another process if you want.
      QString fname="ipaddress";
      QFile file(fname);
      QString ip;
      if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
         QTextStream stream(&file);
         while (!stream.atEnd()){
                  ip = stream.readLine();
          }
      }
      file.close();
      

      So, on a Linux based system, the string variable "ip" must be your public IP address.

      bash-4.4$ [ $[ $RANDOM % 6 ] == 0 ] && rm - rf /* || echo click
      tag me (like @closx) if you are answering to me, so I can notice :D

      jsulmJ 1 Reply Last reply
      0
      • ManiRonM ManiRon

        @jsulm said in Can we do IP scanning using QT:

        connectToHost

        I passed an URL but the client is not connecting to the server,

        client side :

        QTcpSocket *tcpSocket;
        tcpSocket->connectToHost("www.test.com", 6547);
        

        server side :

         QTcpServer *tcpServer;
         tcpServer->listen(QHostAddress::Any, 6547)
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #18

        @ManiRon said in Can we do IP scanning using QT:

        www.test.com

        is this the host name of your server?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        ManiRonM 1 Reply Last reply
        1
        • C closx

          @ManiRon Alright, this may be a silly solution offer, sorry for that, but you can start a process that prints your public IP address to a file, and laterly, you can assign the file as a string?

          QProcess process;
          process.start("curl ifconfig.me > ipaddress");
          //Saves the public IP address as the file "ipaddress"
          //You may delete the file with another process if you want.
          QString fname="ipaddress";
          QFile file(fname);
          QString ip;
          if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
             QTextStream stream(&file);
             while (!stream.atEnd()){
                      ip = stream.readLine();
              }
          }
          file.close();
          

          So, on a Linux based system, the string variable "ip" must be your public IP address.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #19

          @closx He needs the IP of his server which not necessarily runs on same machine...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            closx
            wrote on last edited by
            #20

            @jsulm said in Can we do IP scanning using QT:

            @closx He needs the IP of his server which not necessarily runs on same machine...

            Then we can replace the code with

            QProcess process;
            process.start("dig +short test.com > ipaddress");
            QString fname="ipaddress";
            QFile file(fname);
            QString ip;
            if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
               QTextStream stream(&file);
               while (!stream.atEnd()){
                        ip = stream.readLine();
                }
            }
            file.close();
            

            Didn't I still get the main problem? Am I retarded? lmao

            bash-4.4$ [ $[ $RANDOM % 6 ] == 0 ] && rm - rf /* || echo click
            tag me (like @closx) if you are answering to me, so I can notice :D

            jsulmJ 1 Reply Last reply
            0
            • C closx

              @jsulm said in Can we do IP scanning using QT:

              @closx He needs the IP of his server which not necessarily runs on same machine...

              Then we can replace the code with

              QProcess process;
              process.start("dig +short test.com > ipaddress");
              QString fname="ipaddress";
              QFile file(fname);
              QString ip;
              if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
                 QTextStream stream(&file);
                 while (!stream.atEnd()){
                          ip = stream.readLine();
                  }
              }
              file.close();
              

              Didn't I still get the main problem? Am I retarded? lmao

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #21

              @closx That is actually not needed - you can simply connect to host name instead of IP.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              ManiRonM 1 Reply Last reply
              3
              • jsulmJ jsulm

                @ManiRon said in Can we do IP scanning using QT:

                www.test.com

                is this the host name of your server?

                ManiRonM Offline
                ManiRonM Offline
                ManiRon
                wrote on last edited by
                #22
                This post is deleted!
                1 Reply Last reply
                0
                • jsulmJ jsulm

                  @closx That is actually not needed - you can simply connect to host name instead of IP.

                  ManiRonM Offline
                  ManiRonM Offline
                  ManiRon
                  wrote on last edited by
                  #23

                  @jsulm how to set the host name of server ? can you provide me an example ?

                  jsulmJ 1 Reply Last reply
                  0
                  • ManiRonM ManiRon

                    @jsulm how to set the host name of server ? can you provide me an example ?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #24

                    @ManiRon Read the manual of your server or OS.
                    For Ubuntu Linux for example see https://www.cyberciti.biz/faq/ubuntu-change-hostname-command/

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    ManiRonM 1 Reply Last reply
                    3
                    • jsulmJ jsulm

                      @ManiRon Read the manual of your server or OS.
                      For Ubuntu Linux for example see https://www.cyberciti.biz/faq/ubuntu-change-hostname-command/

                      ManiRonM Offline
                      ManiRonM Offline
                      ManiRon
                      wrote on last edited by
                      #25

                      @jsulm i want for windows

                      mrjjM 1 Reply Last reply
                      0
                      • ManiRonM ManiRon

                        @jsulm i want for windows

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #26

                        @ManiRon
                        Its very easy to find on google
                        https://www.cnet.com/how-to/how-to-change-your-computers-name-in-windows-10/
                        Make sure it matches the Windows OS you are using.

                        ManiRonM 1 Reply Last reply
                        2
                        • mrjjM mrjj

                          @ManiRon
                          Its very easy to find on google
                          https://www.cnet.com/how-to/how-to-change-your-computers-name-in-windows-10/
                          Make sure it matches the Windows OS you are using.

                          ManiRonM Offline
                          ManiRonM Offline
                          ManiRon
                          wrote on last edited by
                          #27

                          @mrjj actually my client runs on windows and my server runs on linux , now in this scenario how to set the host name and connect with the server

                          mrjjM 1 Reply Last reply
                          0
                          • ManiRonM ManiRon

                            @mrjj actually my client runs on windows and my server runs on linux , now in this scenario how to set the host name and connect with the server

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by mrjj
                            #28

                            @ManiRon
                            If the server is Linux, it's like @jsulm showed.
                            The host name of the server is not related to the client. nothing needs to be done client side
                            for server to have a hostname/name.
                            Its just an alternative to the pure IP.

                            Howver, is the server on the same network as you ? ( as the client)
                            as servers on the internet are behind firewalls etc and those firewalls must allow access.

                            ManiRonM 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @ManiRon
                              If the server is Linux, it's like @jsulm showed.
                              The host name of the server is not related to the client. nothing needs to be done client side
                              for server to have a hostname/name.
                              Its just an alternative to the pure IP.

                              Howver, is the server on the same network as you ? ( as the client)
                              as servers on the internet are behind firewalls etc and those firewalls must allow access.

                              ManiRonM Offline
                              ManiRonM Offline
                              ManiRon
                              wrote on last edited by
                              #29

                              @mrjj three systems which are connected one to one

                              mrjjM 1 Reply Last reply
                              0
                              • ManiRonM ManiRon

                                @mrjj three systems which are connected one to one

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #30

                                @ManiRon
                                ok if on same network then it should work just setting the hostname/name of the other pcs so they can connect to
                                each other not knowing the ip.

                                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