How to create an access point using your wifi adapter

Standard

Imagine you have only a ethernet cable and more than a laptop to connect to the Internet (i.e.: your mobile phone, the laptop of a friend and his mobile phone, etc). Imagine you’re in a undergroun Data Center, or in a hotel’s room where you don’t have wifi (for example, in Japan). If you had an Access Point, you could simply connect that cable to it and every device would go through it…

Well, if you have GNU/Linux, you can accomplish it very easily. We’ll see how.

  • [OPTIONAL] Blacklist the manufacturer module

I faced some troubles when I tried to create the ad-hoc connection, and I solved it by blacklisting the manufacturer wmi module, so to see if you have any loaded you can do:

lsmod | grep wmi
acer_wmi 20480 0
sparse_keymap 16384 1 acer_wmi
wmi_bmof 16384 0
rfkill 20480 7 bluetooth,acer_wmi,cfg80211
wmi 20480 2 wmi_bmof,acer_wmi
video 36864 2 acer_wmi,i915
i8042 24576 1 acer_wmi
led_class 16384 4 sdhci,input_leds,acer_wmi,ath9k

As my laptop is an acer, the module obviously is acer_wmi. Select what you guess is yours and blacklist with something like

echo "blacklist acer_wmi" > /etc/modprobe.d/acer.conf

And reboot to apply.

  • Creating it with NetworkManager

With NetworkManager, creating an Access Pointy connection is pretty straight forward. You need to:

  1. Create a Wi-Fi Connection (Shared)
  2. Put a name for the connection (like Access Point Connection)
  3. Put a name for the SSID (like LinuxAP)
  4. On “Wi-Fi Security” tab, select “WPA/WPA2 PSK” and set the password for your network
  5. Save
  6. On the same computer you just created the Access Point network, connect to that “LinuxAP” network with the provided credentials.

Ready, now take your mobile phone and browse the Wi-Fi networs, you’ll see a new one named “LinuxAP” and you will be able to connect to it with the password you’d provide.

To bring down the Access Point, simply use NetworkManager to disconnect from “LinuxAP”. Immediatly, all devices connected will be disconnected as well.

  • Creating an Access Point within the command line

The easiest way to create an access point without NetworkManager is using the script create_ap.

sudo pacman -S create_ap

Once installed, let’s create our Access Point with

# create_ap ap0 WIRELESS_INTERFACE LinuxAP WPA2_PASSWORD

And let it run on a terminal. It will create and adapter called “ap0” as long as the create_ap script runs.

ap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
 link/ether b8:ee:65:1e:13:95 brd ff:ff:ff:ff:ff:ff
 inet 192.168.12.1/24 brd 192.168.12.255 scope global ap0
 valid_lft forever preferred_lft forever
 inet6 fe80::2257:61cf:b9ce:5873/64 scope link 
 valid_lft forever preferred_lft forever

You can grab your mobile phone and connecto to “LinuxAP” using the WPA2_PASSWORD. When you want to bring down the Access Point, just go to the terminal where create_ap is running and Ctrl+C to shut it down.

Note: If you use the create_ap approach, it will blacklist your wireless device in NetworkManager. If you plan to manage that device with NetworkManager, take in mind that you will need to modify /etc/NetworkManager/NetworkManager.conf and comment out or delete the line unmanaged-devices and restart NetworkManager.service.

 

Advertisements

Bash script to download and rip Youtube playlists to mp3

Standard

Recently I’m watching once again Doctor Who. Its soundtrack is simply awesome, so I decided to download it and upload it to google music service to have it both offline and online in all my devices.

On the pirate bay there are only two OSTs of the six seasons. So I searched on youtube and, voilà, there I founded the complete OST for the six seasons. 🙂

So I made a search on AUR to grab a program to download all the videos from those playlist and rip them to mp3. I quickly found youtube-dl and youtube-dl-playlist.

Unfortunately, even though youtube-dl-playlist can donwload (and in my case, most of times, it simply fails to download) a youtube playlist, it does not convert the downloaded items (flv or mp4 videos) to mp3 so we need to use another piece of software in order to get our beloved mp3.

There are so many software for linux we can use to rip off the audio from video, but the simplest one is ffmpeg. In fact, the other software out there requires ffmpeg as dependence… it must be for something…

So I wrote a little bash script that do exactly that: it downloads a entire playlist from youtube and extracts the audio into mp3. Oh, it also takes the image from youtube and put it into mp3 😉

I would like to share it with all of you under the infamous license Do What The Fuck You Want To Public License.

#!/bin/bash
# youtube-dl-playlist-to-mp3
#
# Utility to download Youtube playlist videos and ripp off their audio into mp3
#
# @author Angel Docampo
# @license WTFPL version 2 ( http://sam.zoy.org/wtfpl/COPYING )
echo "This script is useful when you want to download and rip a complete Youtuble playlist into mp3"
echo "Enter a name for the playlist"
read -r NAME
echo "Enter the Youtube playlist URL to begin the process (e.g: http://www.youtube.com/playlist?list=PL3DFF2F30C0A04640 ):"
read PL
mkdir "$NAME" && cd "$NAME"
mkdir .tmp && cd .tmp
youtube-dl -o '%(stitle)s.%(ext)s' $PL
for i in *.flv; do
ffmpeg -i "$i" -acodec libmp3lame -ac 2 -ab 128 "${i%flv}mp3";
done
for i in *.mp4; do
ffmpeg -i "$i" -acodec libmp3lame -ac 2 -ab 128 "${i%mp4}mp3";
done
rm -rf *.flv *.mp4
cd .. && mv .tmp/*.mp3 . && rm -rf .tmp
echo "Conversion finished!"

If you are too lazy to copy and paste it, you can download it from here. Remember to make it executable with chmod +x youtube-dl-playlist-to-mp3 if you named it like that, and put a copy on /usr/bin or /usr/local/bin to make it accessible system-wide.
Of course, you must meet the requirements, those are ffmpeg and youtube-dl installed on your system.

 

EDIT:  You can now download another script that downloads directly the best quality audio file hosted on youtube without the need of transcode it. Credits and complaints to his author

https://github.com/jordoncm/youtube-dl-playlist