Raspberry Pi + Cantenna: Ultimate 2.4GHz Wardriving and Long-range WiFi Access

Want to turn your Raspberry Pi into a portable antenna / wireless router that can be used to pick up WiFi signals from great distances?  I did.  I will walkthrough how to make the 2.4GHz cantenna using some cheap components and then setup the Pi as a router so you could search for WiFi access points, connect to them, and potentially relay the signal. Great for wardriving or just connecting to your home Wi-Fi from out in the backyard.

Requirements For This Walkthrough

Materials

  1. Mac or PC
  2. A cantenna with an N-male to RP-SMA-male cable
  3. A Wi-Fi USB Adapter with removable antenna that does not require a powered USB hub (ideally) or just use the exact model adapter that I used for this walkthrough
  4. Raspberry Pi, model-B running “Wheezy”

Downloads

  1. None

Knowledge, Skills, and Abilities

  • Basic understanding of wireless networking concepts
  • Ability to connect peripherals to a computer
  • Knowledge of basic computer terminology
  • Ability and confidence to enter commands in the Terminal, adjusting them to suit your environment, if necessary

Resources

Connect All Hardware

Connect USB Wi-Fi Adapter

Once the USB adapter is plugged in, run the commandlsusb  to see if there is an entry for the Wi-Fi adapter, then it is ready to go.  Some adapters work out of the box, but others require some more intervention.  I like to keep things easy, so I selected an adapter that I knew would work (plus, it was cheap).

  1. Remove the antenna from the USB adapter if it is connected
  2. Plug the adapter into the RPi
  3. Type the lsusb  on the RPi to see if the adapter is recognized

Depending on what else is plugged into the pi, the command’s output should be similar to the following (look for an entry relating to a wireless adapter).

Bus 001 Device 002: ID 3980:4389 Standard Microsystems Corp. 
Bus 001 Device 001: ID bfde:3293 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID ffe2:380d Standard Microsystems Corp. 
Bus 001 Device 004: ID 4b5a:nd02 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter

Connect Cantenna to the RPi

Connect the cantenna to the the USB adapter using the pigtail cable.

jacob_salmela_cantenna_connected_rpi

Scan for Wireless Network

From the Command Line

Scan for Wi-Fi Access Points

Point the cantenna at an area likely to have access-points.  Scan for wireless networks from the command line (with lots of additional information)

sudo iwlist wlan0 scan

Depending on how many networks there are, there might be a lot of data to sift through.  Most of it is the same information you would find in a GUI app, but it is just a little more messy.  You can pipe the output through a few other commands if you just want the SSIDs.  This is great if you quickly want to see what access points your cantenna is picking up.

sudo iwlist wlan0 scan | grep ESSID | cut -d"\"" -f2 | sort -n

The above command will scan for wireless networks, parse out the SSIDs, cut out the unnecessary information, and then sort it by name.  It is just to make the output more human-friendly.

Alternatively, the following command will show just the most-common information: the SSID, the protocol, the security, and the signal strength.

sudo iwlist wlan0 scan | awk '/ESSID|Quality|IE/' | cut -d"\"" -f2
NETGEAR
     Protocol:IEEE 802.11bg
     IE: WPA Version 1
     Quality=80/100 Signal level=36/100 
UseThisOneMom
     Protocol:IEEE 802.11bgn
     IE: IEEE 802.11i/WPA2 Version 1
     Quality=100/100 Signal level=47/100

Save Commands as Aliases

If you plan to do this a lot, I would suggest making these commands into aliases by adding them to the ~/.bash_aliases  file (creating it if it does not exist).  The other commands are more difficult to save as aliases due to the need to escape the special characters, but the two below should help save time.

alias ssids='sudo iwlist wlan0 scan | grep ESSID | sort -n'
alias ws='sudo iwlist wlan0 scan'

It is necessary to logout and then login before the aliases become active.

From the GUI

Being a command-line junkie, I tend to do things there, but I also appreciate how much easier the GUI can be.  This might be a better way to do it if your Pi is hooked up to a monitor.  If your pi is not booted to the GUI by default, you can start it with the command startx .  It can be permanently enabled via sudo raspi-config

Once booted to the GUI, there should be an app called Wi-Fi Config.  From this app, you can scan the available networks and have all of the same data that was available in the command line presented in an organized way.  With the Pi having limited resources, I tend to choose using the command-line instead, but either option is viable.  Use whatever you like!

Connect to an Available SSID

From the Command Line

Now that you can see what networks are available, you need to edit a config file to connect to it.  Most likely, you will be connecting to an SSID where you know the password (unless you are wardriving).  So just open /etc/network/interfaces  in a text editor

sudo vi /etc/network/interfaces

The following four lines should be in the file (some may be there already)

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Next, edit /etc/wpa_supplicant/wpa_supplicant.conf  with the specifics of the network you are attempting to connect to

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

The file should look similar to the following (but with your network settings in place)

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="YOURSSID"
psk="YOURPASSWORD"

# Protocol type can be: RSN (for WP2) and WPA (for WPA1)
proto=WPA

# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
key_mgmt=WPA-PSK

# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
pairwise=TKIP

#Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP)
auth_alg=OPEN
}

Reboot to apply all of the settings

sudo reboot

From the GUI

Use the Wi-Fi Config app (usually, it is on the Desktop) to choose the network to connect to.

NEW Linksys RE6500 Wireless AC Range Extender 300x250

Other Ideas for the Pi + Cantenna

17 Replies to “Raspberry Pi + Cantenna: Ultimate 2.4GHz Wardriving and Long-range WiFi Access”

  1. Hi Jacob,

    excellent tutorial. Do you think it would it be possible to relay the wireless signal through the RPi Ethernet port to another device? For example a router that would serve other wired devices ?

    Thanks!

    1. I haven’t tried this, but it seems to me you could hook it up to a switch and then plug your devices in there, but the RPi only has one ethernet port… But then you couldn’t get out to the Internet since the port is being used for the switch. The only other thing I can think is if there is some way to set up the RPi as a “relay” AP–basically connect it wirelessly to another network and then use the hardline for the switch.

  2. Hi Jacob,
    I am a trainee teacher and have just been on a two day Pi Academy, I had an idea of setting up a Pi based long range network challenge and found your blog. I was thinking of setting up a challenge / competition for Schools and poss the Pi community in general to see who can establish the longest WiFi network.
    There will be a set of rules on what you can and cannot use to keep it fair.
    Would you mind if I used some of your info above.
    I have built several different waveguide antennas in the past (2004 ish) so its the Pi settings mainly. Just didn’t want to Magpie without asking.

    Many thanks

    1. Yes, you can. Thanks for asking! Please link back to my site if you post any online materials.

      It sounds like fun. I would be interested to learn about the results.

  3. Hi, great tutorial.
    I’m trying to create a shooting target camera that will provide video stream or still pictures to around 430 yrds away to an iPad. It is all line of sight with no obstructions between the shooting bench and target.

    Is this kind of distance achievable? Or do I need some type of repeater?
    Or, is there some more realistic way other than wifi that I need to look in to?

    Thanks for helping a noob.

    1. The farthest away I have been able to get a signal is across a lake. I don’t know how far it was, but unobstructed, it can go a lot farther than you might think.

      I do know of people who made a cantenna out of an old satellite dish and were able to send it several miles. Another option is to build a bi-quad antenna, but both are quite more difficult to make.

      1. Thanks so much!
        I do think the cantenna will be the way to go.

        I’ve seen something where one uses an old dish network dish, but being at a shooting range I’m not sure I trust folks not to shoot it up. 🙂 maybe the Pringles can is the way to go.

        Would there be any benefit to having a second Rpi to act as the receiver vs just having one’s phone or iPad be the receiver? I was thinking it might be good to have a second RasPi that I could plug in a WiFi antenna. Thoughts?

        1. Two cantennas pointed at each other would definitely improve the range, but it might be difficult to align them well over such a long distance.

          You can also adjust the size of the can (or make your own). A stock can from a store is just an approximate match. If you follow the formula for determining the can size, you could create your own.

          Other things, like how reflective the inside of the can is, how long the element is (even +/- a few mm), or where it is placed in the can can make a difference.

          The 2.4GHz spectrum isn’t just exactly 2.4; it has different frequencies such as 2.412 or 2.472. So even small variations in your measurements can make a difference.

          1. You’re welcome. The cantenna was one of my favorite projects, so it’s fun to talk to someone else about it.

  4. Hey, nice tut 🙂
    A tiny tip: Bash aliases can be reloaded without logging off and back on again.
    In the terminal, type “source ~/.bash_aliases” (no quotes) or “. ~/.bash_aliases” (note the dot in the beginning. again, no quotes)
    Cheers!

    1. Good point! I discovered this some time after making this post, but never went back to edit this post. Did you get your cantenna working?

      1. actually, i was just browsing through the internet and saw this interesting post, so nope….. sorry 🙂

Leave a Reply