Important: Please read the Qt Code of Conduct -

Check the ip connect to QWebSocketServer is external or local ip

  • My purpose is build a server-client app, the server should listen to the devices in the local network only, is it possible to check the ip try to connect to the server are come from local network or not?Thanks

  • Lifetime Qt Champion


    That's rather something you should do at the system level with something like iptables. If you don't want your server to get accessed from outside of your network, then don't allow network connection from the outside to happen in the first place.

  • Moderators

    you mean checking if the ip is in the private ip range?

    QHostAddress clientIp(...);
    if( !clientIp.isInSubnet( QPair<QHostAddress, int>("", 8) &&
         !clientIp.isInSubnet( QPair<QHostAddress, int>("",12) &&
         !clientIp.isInSubnet( QPair<QHostAddress, int>("",16) )
         // not in private ipv4 range

Log in to reply