-1

I am building an attendance application for my college, where in I want to mark student attendance through the network. Every class room has seperate router and I want to basically check if student are sitting in the router's range and mark their attendance accordingly. How can I check if there are sitting in router's range, is this possible through web socket? or How can I ping or do something through web sockets to check if particular ip is alive or not?

I am using kotlin to develop my application. Please help.

  • 1
    There are major ethical concerns with this sort of thing. Automated surveillance. Seek legal advice before proceeding. You should make the students do something active, e.g. login, to get their attendance noted. – user207421 Mar 05 '18 at 04:22
  • And what if a student doesn't bring in a device that connects to a classroom's router? Is such a device mandatory for *every* class a student attends? How do you plan on remotely querying each router for its connected devices? Requiring a student to login to a web-based app would be more appropriate. – Remy Lebeau Mar 05 '18 at 20:07
  • Well, there is a login provision and also to make sure the student is in the class, I need to know student is connected to which router. And if student doesnt have a device, there are other alternatives as well to get the attendance marked. – Devanshi Sukhija Mar 06 '18 at 06:20
  • Whats the problem with those who down vote? SO should make down voters explain their reason. This is a good question in my opinion and has lots of different solutions. – Sepehr GH Mar 06 '18 at 07:24

5 Answers5

0

You can ping an IP. However, it seems each student should be granted a permanent local IP for each class. This is an example how to ping to an IP:

fun ping(ip: String): String {
        var str = ""
        try {
            val process = Runtime.getRuntime().exec(
                    "/system/bin/ping -c 8 " + ip)
            val reader = BufferedReader(InputStreamReader(
                    process.inputStream))
            var i: Int
            val buffer = CharArray(4096)
            val output = StringBuffer()
            i = reader.read(buffer)
            while (i > 0) {
                output.append(buffer, 0, i)
                i = reader.read(buffer)
            }
            reader.close()
            str = output.toString()
        } catch (e: IOException) {
            e.printStackTrace()
        }

    return str
}
Cao Minh Vu
  • 1,900
  • 1
  • 16
  • 21
0

Instead of checking via IP address, why cant you make your user to login into the application, only when he/she is within a particular co-ordinate or GPS position. In this way, even if your IP address changes in future, app need not to be updated.

In your server keep your list of locations for each class. Only when the student is within the location range, he/she should be allowed to login to the application.

Refer Check if a latitude and longitude is within a circle for more details.

Gokul Nath KP
  • 15,485
  • 24
  • 88
  • 126
  • This needs more battery usage and more accesses for the android app and still can be faked or face lots of problems (too slow sometimes) – Sepehr GH Mar 06 '18 at 07:11
0

The only location you can find this is in the ARP table of the routers. The end-point isn't guaranteed to return anything it hasn't asked for, while the router needs this information to properly address the traffic back to the end-point.

MavEtJu
  • 41
  • 6
0

How can I ping or do something through web sockets to check if particular ip is alive or not?

You cant force a client to allow you to ping them just using their ip address. The best way to go is to connect your users to a central server (through a websocket in your example) and check heartbeats on the websocket.

For this, of-course you have to first authorize your students and make sure everyone has a token on their websocket so that you can track their existence in your system. Then you need some kind of heartbeat system. Most websocket implementations I have seen, have already implemented ping and pong. It can work both ways:

One point, to check if other point is connected should send ping requests and the other point automatically sends back a pong message if they are connected.

In an app we wrote, we have an interval to send pings to clients, and we persist their pong timestamp. If last pong timestamp is too old, then we know that connection is failed or client is not available on the network.

Although, if websocket closes or faces an error, a method (like onError() and onClose()) gets called and you are informed. But implementing an heartbeat service can help you make sure your connection is actually alive and is a MUST in your websocket based system.

How can I check if there are sitting in router's range, is this possible through web socket?

If Im not wrong, you are in charge of designing both sides of your application (client and server). So, you can make users try to connect to your LOCAL ip address again and again until the connection is successful. You just have to make sure your server ip address is reachable through those other routers.

NOTE: on the local network, if students should not be able to connect using another classroom router, then you can check their websocket ip address. Before that there should be an table to map each user to the ip address they can send message from.

Another way to achieve this IF YOUR SERVER IS NOT IN THAT LOCAL NETWORK is to give those routes same public ip address (or static ip addresses), and route your traffic through internet to your server public ip address. Then to make sure users can only connect from those routers (within range of those routers), you have to allow those routers IP address in your server firewall (or you can do it in the server application side) and block any other connections on your websocket port.

NOTE 2 again, if your server is not in your local network, but you still want to make sure each user is in its valid classroom, you need a proxy server. works like this:

Client connects to its classroom router > router connects to local proxy server > proxy server adds router ip address to websocket message and sends it to public server > public server can process message and has user local ip address

Sepehr GH
  • 1,297
  • 1
  • 17
  • 39
0

Yet another variation

def can_ping(ip, port=80, timeout=5):
    """Verify connection to ip/port"""
    try:
        socket.setdefaulttimeout(timeout)
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((ip, port))
    except OSError:
        # enter block when exception is thrown
        result = False
    else:
        # enter block on success
        result = True
    finally:
        # always run block
        s.close()
    return result
>>> ping("192.168.0.1")
True
>>> ping("192.168.0.-1")
False
>>> ping("192.168.aaaa")
False
aidanmelen
  • 6,194
  • 1
  • 23
  • 24