Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Solved Check the ip connect to QWebSocketServer is external or local ip

    General and Desktop
    3
    3
    205
    Loading More Posts
    • 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.
    • tham
      tham last edited by

      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

      raven-worx 1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 3
        • raven-worx
          raven-worx Moderators @tham last edited by

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

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply Reply Quote 2
          • First post
            Last post