启用/通过在Android上的bash脚本禁用无线网络 [英] Enable / disable wifi via bash scripting on Android

查看:658
本文介绍了启用/通过在Android上的bash脚本禁用无线网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想启用/禁用无线设备在我的Andr​​oid设备中的bash脚本。我使用的终端仿真程序,程序脚本管理器到手机(这是一个根深蒂固的Nexus One)上执行的bash脚本。 正常的方式来做到这一点,在linux会是这样

I am trying to enable / disable the wifi device in my android device in a bash script. I am using the terminal emulator and the program Script Manager to execute bash scripts on the phone (which is a rooted Nexus One). The normal way to do this in linux would be something like

ifconfig eth0 up 

这给了我

"eth0: no such device"

尝试     的iwconfig eth0的 给出了相同的,以及

Trying iwconfig eth0 gives the same, and

iwconfig 

给设备上面没有eth0的列表。现在,如果我打开无线网络(手动从GUI),然后键入

gives a list of devices with no eth0 on it. Now if I turn on wifi (manually from the GUI) and type

iwconfig

它显示为eth0有很多信息。

it shows eth0 with a lot of info.

我的问题是:我如何用命令行打开/关闭WiFi?为什么是eth0的从设备列表中消失时,无线被禁用?

My question is: How can I use the command line to turn on / off wifi? And why is eth0 disappearing from the device list when wifi is disabled?

感谢。

推荐答案

虽然它并不在我的无根的手机的原因很明显的工作,结果我得到的,而WiFi是连接完全不同的:

While it doesn't work in my non-rooted phone for obvious reasons, the results I'm obtaining are completely different while wifi is connected:

$ ifconfig eth0
eth0: ip 192.168.0.102 mask 255.255.255.0 flags [up broadcast running multicast]
$ ifconfig eth0 up
error: SIOCSIFFLAGS (Permission denied)

如果你只是想打开WiFi或关闭你应该使用:

If you just want to turn wifi on or off you should use:

# svc wifi enable

# svc wifi disable

要查看帮助信息

# svc wifi
Control the Wi-Fi manager

usage: svc wifi [enable|disable]
         Turn Wi-Fi on or off.

       svc wifi prefer
          Set Wi-Fi as the preferred data network

这篇关于启用/通过在Android上的bash脚本禁用无线网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆