Jump to content
Hak5 Forums
Sign in to follow this  
haze1434

[BASH] How to disable external wifi card within shell script?

Recommended Posts

Hi all,

I am creating some shell scripts that occasionally need to use an external Alfa WiFi card, but not all of the time.

Rather than leaving the Alfa card enabled constantly, I would like the script to bring the card online when it is required, and switch it back off when it is not.

I have read various methods to do this online, but none seem definitive, so I would like to ask which method I should use.

So far, I have seen suggestions of;

  • Using WLAN# up and WLAN# down
  • Disabling USB ports using Hub-CTRL
  • Using hardware add-ons
  • This or this (unknown what is being done here)
  • Even people saying it's not possible.

 

What would you suggest? Has anyone else had any luck with switching off and back on an Alfa Wifi Card from a Linux command line/script?

I haven't yet played around, as I'm not at home, but I don't want to waste my time trying a method that won't work as well as something else.

Thank you.

 

Share this post


Link to post
Share on other sites
18 minutes ago, haze1434 said:

Using WLAN# up and WLAN# down

This is the best solution for a bash script.

 

 

  • Upvote 1

Share this post


Link to post
Share on other sites

For ifupdown, has to be setup for it, no? Why can't you just ifconfig wlan3 down/up, etc?

  • Upvote 1

Share this post


Link to post
Share on other sites

Are you looking to reduce power consumption (running off battery) or just looking to not have the wireless visible to the world?  If you are not worried about any additional power consumption I think you would be fine just using ifconfig <interface> down / up in a shell script and be fine.  If you are looking for power savings this may be a little more difficult (I'm assuming).

  • Upvote 1

Share this post


Link to post
Share on other sites
Posted (edited)
8 hours ago, dbum said:

Are you looking to reduce power consumption (running off battery) or just looking to not have the wireless visible to the world?  If you are not worried about any additional power consumption I think you would be fine just using ifconfig <interface> down / up in a shell script and be fine.  If you are looking for power savings this may be a little more difficult (I'm assuming).

Thanks. I'm looking to not have the wireless on at all, until I require it.

At the moment, the Alfa external Wi-Fi card comes on as the Raspberry Pi boots up, and stays on until it shuts down.

I don't use the Wi-Fi card all of the time, so rather than a 'low-power' mode when it's not in use, I'd like to literally just switch it off / supply it no power at all.

Basically, the equivalent of unplugging the Wi-Fi card from the USB slot, but without having to physically unplug it.

 

To give a better overview; This is for a home automation project where the Raspberry Pi will be switched on pretty much all of the time, but I don't want the external Wi-Fi antenna to be kicking out a signal all of the time, as it's a quite high powered antenna and I'd rather not sit in the radiation 24/7, no matter how small. For peace of mind, I'd rather just switch it off when not in use. Plus it also does use a battery back up, and if it's in this mode, the battery will be drained pretty quickly.

Edited by haze1434

Share this post


Link to post
Share on other sites

If your handy with hardware, you could use a normally open (NO) reed relay to connect/disconnect the red power usb wire. reed relays are typically very low current to switch on/off and I think the raspberry pi should be able to do that. Just need to hook it up to one of the GPIO pins.
https://en.wikipedia.org/wiki/Reed_relay

Share this post


Link to post
Share on other sites

Ok.  So I did some testing this morning and this is what I came up with (it has been hectic at work today so I haven't been able to post until now):

This was using an Alpha AWUS036 and monitoring the output (from another device - Mikrotik) and also monitoring the power going to the Raspberry pi 2

Here was my setup:

J4NXOQF.png
My Pi, Mikrotik mAP and Alpha AWUS036

 

W3bI0T2.png
With antenna on - this was steady and remained the same through the duration (increasing txpower on antenna from 100mw to 1000mw)

 

dPzgrZY.png
At 100mw

 

EvdcjRF.png
At 1000mw

 

So, just running the command 'ifconfig wlan0 down'

Does turn off the Green LED on the device and

 

m44uNh2.png
monitor no longer registers

 

NiGcYtE.png
Input power is greatly reduced (This stayed like this until turning the interface back on)

 

It really appears that using ifconfig (could be used in whatever shell scripts you are using / cron / etc.) actually cuts the power to the device or at least puts it into a very low power state.

 

Hope these findings help you on your journey!

  • Upvote 2

Share this post


Link to post
Share on other sites
16 minutes ago, dbum said:

Hope these findings help you on your journey!

Could you measure it while running airodump-ng, or a deauth attack?

 

Share this post


Link to post
Share on other sites

Sure, but it may be Sunday or Monday until I can get to it.  Busy weekend planned.  I'm not sure that ether measurements will vary too much.  It seemed like the input power stayed fairly constant under different txpower (didn't try pushing huge amounts of data though) and I really don't think that would make the antenna power change.  I can look into further as soon as I have a little time though.  I had to cut testing short this morning to get to work :(

  • Upvote 1

Share this post


Link to post
Share on other sites

I guess that I could get a USB cable and cut it then run it through a multi-meter and see if any power is going through it after the ifconfig statement.  I ran across this as well that I bet you could adapt to fully remove usb connectivity by controlling it with the Pi's IO pins

https://www.cdw.com/shop/products/IOGEAR-2-Port-USB-2.0-Auto-Sharing-Switch/1691857.aspx?cm_cat=GoogleBase&cm_ite=1691857&cm_pla=NA-NA-IOR_US&cm_ven=acquirgy&ef_id=V4kGJwAABFSiqux7:20170623210440:s&gclid=CjwKEAjw-LLKBRCdhqmwtYmX93kSJAAORDM6sHEZfyy7JaDajuRpdaABZ3lpakpL5x3yovoyipiHIRoCK7jw_wcB&s_kwcid=AL!4223!3!198553132056!!!g!369923655287!

  • Upvote 1

Share this post


Link to post
Share on other sites
1 hour ago, dbum said:

I guess that I could get a USB cable and cut it then run it through a multi-meter and see if any power is going through it after the ifconfig statement.  I ran across this as well that I bet you could adapt to fully remove usb connectivity by controlling it with the Pi's IO pins

https://www.cdw.com/shop/products/IOGEAR-2-Port-USB-2.0-Auto-Sharing-Switch/1691857.aspx?cm_cat=GoogleBase&cm_ite=1691857&cm_pla=NA-NA-IOR_US&cm_ven=acquirgy&ef_id=V4kGJwAABFSiqux7:20170623210440:s&gclid=CjwKEAjw-LLKBRCdhqmwtYmX93kSJAAORDM6sHEZfyy7JaDajuRpdaABZ3lpakpL5x3yovoyipiHIRoCK7jw_wcB&s_kwcid=AL!4223!3!198553132056!!!g!369923655287!

Could you also use the board to power off the USB port like an energy saver? Then power the port back on, which would also re-detect he hardware plugged in. I think that would also probably help reduce battery drain for devices looking to conserve, but you;d have to test that theory.

  • Upvote 1

Share this post


Link to post
Share on other sites
1 minute ago, digip said:

Could you also use the board to power off the USB port like an energy saver? Then power the port back on, which would also re-detect he hardware plugged in. I think that would also probably help reduce battery drain for devices looking to conserve, but you;d have to test that theory.

I can try that as well when I get my rig set up.  Probably be Monday.

  • Upvote 2

Share this post


Link to post
Share on other sites
On ‎23‎/‎06‎/‎2017 at 7:54 PM, dbum said:

Hope these findings help you on your journey!

Thank you for this, I didn't get a chance to play over the weekend (too much DIY to do around the house!).

Much appreciated, and good info :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×