在 Android 上通过 bash 脚本启用/禁用 wifi

发布于 2024-11-16 16:49:06 字数 521 浏览 2 评论 0原文

我正在尝试在 bash 脚本中启用/禁用 Android 设备中的 wifi 设备。我正在使用终端仿真器和程序脚本管理器在手机(是 root 的 Nexus One)上执行 bash 脚本。 在 Linux 中执行此操作的正常方法是这样的

ifconfig eth0 up 

That Gives me

"eth0: no such device"

Trying iwconfig eth0 给出相同的结果,并

iwconfig 

给出没有 eth0 的设备列表。现在,如果我打开 wifi(从 GUI 手动)并键入,

iwconfig

它会显示 eth0 以及大量信息。

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

谢谢。

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 

That gives me

"eth0: no such device"

Trying
iwconfig eth0
gives the same, and

iwconfig 

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

iwconfig

it shows eth0 with a lot of info.

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?

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-黛色若梦 2024-11-23 16:49:06

虽然由于显而易见的原因,它在我的未 root 手机中不起作用,但在连接 wifi 时,我获得的结果完全不同:

$ 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,则应该使用:

# 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

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)

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

# svc wifi enable

or

# svc wifi disable

to see the help message

# 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文