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 Can you explain what you want to do? Do you want something like service discovery? Do you want to search for your server without knowing its IP? You could use UDP broadcast (you can do this with Qt), see http://www.cs.ubbcluj.ro/~dadi/compnet/labs/lab3/udp-broadcast.html for some explanation. Your server will need to answer on that broadcast. There are more advanced techniques, see https://en.wikipedia.org/wiki/Service_discovery

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

    @jsulm I want to find the server without knowing its ip and connect with it and i want it in TCP

    jsulmJ 1 Reply Last reply
    0
    • ManiRonM ManiRon

      @jsulm I want to find the server without knowing its ip and connect with it and i want it in TCP

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

      @ManiRon Well, you can try to connect to all valid IP addresses in your network (subnet mask defines valid IPs), but that can take time.

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

      ManiRonM 1 Reply Last reply
      0
      • jsulmJ jsulm

        @ManiRon Well, you can try to connect to all valid IP addresses in your network (subnet mask defines valid IPs), but that can take time.

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

        @jsulm Ya i tried it and it takes time , thats why i am looking for an alternative

        jsulmJ 1 Reply Last reply
        0
        • ManiRonM ManiRon

          @jsulm Ya i tried it and it takes time , thats why i am looking for an alternative

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

          @ManiRon Alternative is service discovery (or UDP broadcast, after broadcast you can do TCP as usual)...

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

          ManiRonM 1 Reply Last reply
          5
          • jsulmJ jsulm

            @ManiRon Alternative is service discovery (or UDP broadcast, after broadcast you can do TCP as usual)...

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

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

            But for UDP broadcast i might have to implement some coding on my server side , which i might not be able to do . whether we can use UDP broadcast without modifying the server side

            jsulmJ 1 Reply Last reply
            0
            • ManiRonM ManiRon

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

              But for UDP broadcast i might have to implement some coding on my server side , which i might not be able to do . whether we can use UDP broadcast without modifying the server side

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

              @ManiRon Can't you give your server a DNS name? And then simply connect to that name instead of an IP?

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

              ManiRonM 1 Reply Last reply
              1
              • jsulmJ jsulm

                @ManiRon Can't you give your server a DNS name? And then simply connect to that name instead of an IP?

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

                @jsulm I have to check this way , will there be any samples available ?

                jsulmJ 1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kuzulis
                  Qt Champions 2020
                  wrote on last edited by kuzulis
                  #12

                  You can try to use the nmap utility or its library to do a network scanning.

                  ManiRonM 2 Replies Last reply
                  0
                  • K kuzulis

                    You can try to use the nmap utility or its library to do a network scanning.

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

                    @kuzulis it is a little tough to understand and the flow of the code is also tough to understand, Thats why looking for an alternate way

                    1 Reply Last reply
                    0
                    • K kuzulis

                      You can try to use the nmap utility or its library to do a network scanning.

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

                      @kuzulis i am not having clarity on how to use its library file with my application

                      1 Reply Last reply
                      0
                      • ManiRonM ManiRon

                        @jsulm I have to check this way , will there be any samples available ?

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

                        @ManiRon Pass an URL to connectToHost instead of IP

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

                        ManiRonM 1 Reply Last reply
                        1
                        • 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

                                          • Login

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