Solved 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
-
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.
-
@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 }