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

    Hi,

    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

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

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

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.