Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am writing an application that uses a mysql backend to store a users temporary

ID: 3532345 • Letter: I

Question

I am writing an application that uses a mysql backend to store a users temporary username and randomly connect that user with another user, similar to omegle i have that written as well as some ajax running on the client side to update the div when new rows are inserted,what i want to do is control who connects to who based on what internet they are connected to. For example if one user is connected to the campus wifi then he would only connect to another user using the campus wifi network. i can read the IP of the connecting client wtih a built-in php function how do i check to see if that IP is on a particular subnet, when i pull up a command prompt i type in IPCONFIG and it gives me the IPv6 the IPv4 the subnet mask and the default gateway how can i use that information to see if connecting clients are on the same network      this is for a class final project

Explanation / Answer

The idea is that we calculate the subnet mask by setting the most significant bits to 1, as many as dictated by the subnet class. For a class C, that would be

Then, AND the subnet mask with the IP address you have; if the IP is inside the subnet, the result should be equal to the subnet address -- standard networking stuff. So we end up with:

Update:Yes, it is necessary to know the network classorthe subnet mask (which is equivalent information). Consider how could you handle the case where the subnet isX.Y.0.0if you did not have this information. Is thisX.Y.0.0/16orX.Y.0.0/8where the third octetjust happensto be 0? No way to know.

If you do know the subnet mask, then the query can be written as

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote