-5

For an application, I need to get a list of IPs that are connected to the wifi router.

How can we implement this using Java language to get the list.

  • 2
    This link could be helpful: http://stackoverflow.com/questions/3345857/how-to-get-list-of-ip-connected-in-lan-using-java – Bruno Franco Aug 21 '14 at 12:59
  • No. `netstat -r` will not list all ips connected to a wifi router. Does it need to work with *any* router, or is there a specific one? Is this a consumer grade router, or a corporate router? – Elliott Frisch Aug 21 '14 at 13:01
  • `netstat -r` will not give you the list of IP connected to a router (wiffi or not). It will just print the known route to IPs per interface. – ortis Aug 21 '14 at 13:02
  • 3
    Step 1: Pick a language. Step 2: ? Step 3: Profit. – Captain Obvlious Aug 21 '14 at 13:05
  • Hello @CaptainObvlious, 1. I've the ability to understand any of the languages listed. 2 & 3. Its an application which can be implemented out of it. 4. Give suggestions not the down vote. – Shiva Kumar Ganthi Aug 21 '14 at 13:07
  • @CaptainObvlious Thanks cap, you're helped a lot today! – EDUsta Aug 21 '14 at 13:09
  • Oh Sorry! and thanks for letting me know when I execute the command it listed the IPs of me and my friends who connected to the same router. So, I thought like that. @ortis – Shiva Kumar Ganthi Aug 21 '14 at 13:10

1 Answers1

2

If you need to programmatically recreate the behaviour of netstat then read and parse the corresponding /proc/net files.

From /proc/net/protocols you can find the different type of sockets.

From /proc/net/tcp (for example) you can find the TCP connections, etc.

Example:

$ cat /proc/net/protocols 
protocol  size sockets  memory press maxhdr  slab module     cl co di ac io in de sh ss gs se re sp bi br ha uh gp em
[...]
UDP        888      3       2   NI       0   yes  kernel      y  y  y  n  y  n  y  n  y  y  y  y  y  n  y  y  y  y  n
TCP       1760      6       1   no     304   yes  kernel      y  y  y  y  y  y  y  y  y  y  y  y  y  n  y  y  y  y  y
[...]
$ cat /proc/net/tcp
  sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode                                                     
   0: 0100007F:1F90 00000000:0000 0A 00000000:00000000 00:00000000 00000000    99        0 9538 1 ffff8800db768000 99 0 0 10 0                       
   1: 0100007F:1F91 00000000:0000 0A 00000000:00000000 00:00000000 00000000  1000        0 10954 1 ffff8800dab78000 99 0 0 10 0       
[...]

0100007f, for example, is hexadecimal for 127.0.0.1.