============================================================
博文原创,转载请声明出处
============================================================
最近在获得路由ip地址时候遇到了麻烦,在iphone中我们可以从设置中看到网关地址,但是ios官方并不提供接口去获得网关地址。
最终自己做了demo来,已经上传到github,地址:https://github.com/ygweric/IOS-RouteAddress
不过存在的问题是只能获得网关地址是192.168.x.x范围的地址,对于其他网段不好使,不好解决,如果有朋友知道希望留言告知啊 ^_^.
最终输出结果是:
2012-11-26 13:06:48.102 RouterAddressDemo[451:907] broadcast address--192.168.1.255
2012-11-26 13:06:48.108 RouterAddressDemo[451:907] local device ip--192.168.1.221
2012-11-26 13:06:48.111 RouterAddressDemo[451:907] netmask--255.255.255.0
2012-11-26 13:06:48.114 RouterAddressDemo[451:907] interface--en0
2012-11-26 13:06:48.116 RouterAddressDemo[451:907] local device ip address----192.168.1.221
gateway address--192.168.1.1
2012-11-26 13:06:48.118 RouterAddressDemo[451:907] r--0
2012-11-26 13:06:48.120 RouterAddressDemo[451:907] --starttime:1353906408,endtime:1353906408
2012-11-26 13:06:48.122 RouterAddressDemo[451:907] time cost getting above info is--0s