android ndk开发中常用的系统自带网络命令

android本身内置了一些网络命令,使用这些命令程序尤其基于ndk开发时会获得很多便利,并在某种程度上可以绕开上层的限制、获得更多详细的信息和更好的灵活性等。


1.操作路由表

获取:ip route 或者 busybox route

新增:ip route add 10.0.0.172/8 dev wlan0

删除:ip route del 10.0.0.172

删除一条默认路由:ip route del default

添加默认路由:route add default gw 10.0.0.172

2.测试网络

ping 10.0.0.172

测试DNS:busybox nslookup blog.csdn.net

测试DNS:dsdnsutil -s 114.114.114.114 -q blog.csdn.net

测试路由路径:busybox traceroute 10.0.0.172

3.查看接口

netcfg

netcfg rmnet0

busybox ifconfig (和route类似,android自带的ifconfig默认不会打印出接口信息)

4.操作接口

netcfg wlan0 up/down

netcfg wlan0 dhcp up

ifconfig rmnet0 10.0.0.172 up

ifconfig rmnet0 10.0.0.172 netmask 255.0.0.0 up

5.系统属性

打印全部属性:getprop

设置DNS:setprop net.dns1 128.224.160.11   // 此外 net.dns2 类似,不过在我的机子上好像无效,最终采用的dns是dhcp.wlan0.dns1指定的值

6.无线wifi

打印无线拓展:iwconfig

使用netcfg打印接口,在wifi没有打开的情况下是没有wlan0接口的,因为wifi内核模块并未加载,

加载wifi驱动模块:insmod /system/lib/modules/wlan.ko  (这时候wlan0就出来了,补充:后续可以参考这篇文章Android下同时使用WIFI与3G网络。)

卸载wifi驱动模块: rmmod /system/lib/modules/wlan.ko  (注意手动加载后没有卸载的话用户界面是开不了wifi的)

扫描wifi热点:iwlist wlan0 scanning

7.ndc命令(需要ROOT权限)

interfacelist
readrxcounter| readtxcounter
getthrottle <iface> <”rx|tx”>
setthrottle <iface> <rx_kbps|tx_kbps>
driver <iface> <cmd> <args>
route <add|remove> <iface> <”default|secondary”> <dst> <prefix> <gateway>
list_ttys  
ipfwd status
enable|disable
tether status
start-reverse|stop-reverse
stop<
start<addr_1 addr_2 addr_3 addr_4 [addr_2n]>
interface <add | remove | list>
dnslist
dnsset <addr_1> < addr_2>
nat <enable | disable> <iface> <extface> <addrcnt> <nated-ipaddr/prelength>
pppd attach <tty> <addr_local> <add_remote> <dns_1> <dns_2>
detach <tty>
softap startap | stopap
fwreload <iface> <AP|P2P>
clients
status
set <iface> <SSID> <wpa-psk|wpa2-psk|open> [<key><channel> <preamble> <max SCB>]
resolver setdefaultif <iface>
setifdns <iface> <dns_1> <dns_2>
flushdefaultif   刷新DNS缓存
flushif <iface>
bandwith enable | disable
removequota | rq
getquota | gq
getiquota | giq <iface>
setquota | sq <bytes> <iface>
removequota | rqs <iface>
removeiiquota | riq <iface>
setiquota | sq <interface> <bytes>
addnaughtyapps | ana <appUid>
removenaughtyapps | rna <appUid>
setgolbalalert | sga <bytes>
debugsettetherglobalalert | dstga <iface0> <iface1>
setsharedalert | ssa<bytes>
removesharedalert | rsa
setinterfacealert | sia <iface> <bytes>
removeinterfacealert | ria <iface>
gettetherstats | gts <iface0> <iface1>
idletimer enable|disable
add|remove <iface> <timeout> <classLabel>
firewall enable|disable|is_enabled
set_interface_rule <rmnet0> <allow | deny>
set_egress_source_rule <ip_addr> <allow | deny>
set_egress_dest_rule <ip_addr> <port> <allow | deny>
set_uid_rule <uid> <allow|deny>
clatd stop | status| start <iface>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值