Recently, I encountered a problem when obtaining the Route IP address. On the iphone, we can see the gateway address from the settings, but the ios official does not provide an interface to obtain the gateway address.
Finally, I made a demo myself,
However, the problem is that only the IP address in the range of 192.168.x.x can be obtained, which is difficult to solve for other network segments. If a friend knows that he wants to leave a message ^_^.
The final output result is:
[Cpp]
13:06:48. 102 RouterAddressDemo [451: 907] broadcast address -- 192.168.1.255
13:06:48. 108 RouterAddressDemo [451: 907] local device ip -- 192.168.1.221
13:06:48. 111 RouterAddressDemo [451: 907] netmask -- 255.255.255.0
13:06:48. 114 RouterAddressDemo [451: 907] interface -- en0
13:06:48. 116 RouterAddressDemo [451: 907] local device ip address ---- 192.168.1.221
Gateway address -- 192.168.1.1
13:06:48. 118 RouterAddressDemo [451: 907] r -- 0
13:06:48. 120 RouterAddressDemo [451: 907] -- starttime: 1353906408, endtime: 1353906408
13:06:48. 122 RouterAddressDemo [451: 907] time cost getting abve info is -- 0 s