Ubuntu を アクセスポイント化しよう
Linuxで無線LANが使用できる環境なら、簡単にそのLinux PCをアクセスポイント化できます!
Linuxすげ〜。。これには感嘆しました!早速その恩恵にあやかりましょう!笑
手順
1.Network-Managerの無効化
$ sudo stop network-manager $ sudo -i # echo "manual" | tee /etc/init/network-manager.override
関連
How to disable Network Manager on Linux - Xmodulo
NetworkManager - Community Help Wiki
※補足
私はこれにハマりました。。
これをしないと hostapd -dd /etc/hostapd/hostapd.conf でhostpdの動作確認を行うと、”nl80211 driver initialization failed.
”というエラーになります。
どうやら、無線LANのドライバはNetwork-Managerによって制御されてしまうようなので無効化します。
2.パッケージのインストール、設定ファイルの作成、動作確認
$ sudo apt-get install hostapd $ sudo -i # zcat /usr/share/doc/hostapd/examples/hostapd.conf.gz > /etc/hostapd/hostapd.conf
※hostapd.confの編集は、以下のサイトに倣って編集。(ssid, wpa_passphraseは適宜変更。セキュリティを高めるためwpa_pairewise=CCMPに変更)
http://cberner.com/2013/02/03/using-hostapd-on-ubuntu-to-create-a-wifi-access-point/
hostapdのinitscriptでhostapd.confのパスを指定
$ sudo vi /etc/default/hostapd DEMON_CONF="/etc/hostapd/hostapd.conf"
関連
Ubuntu 12.10 を無線LANルーターにする - @tmtms のメモ
ここまででひと通りhostapdの設定は完了なので、動作確認をしてみましょう!
$ sudo hostapd -dd /etc/hostapd/hostapd.conf
エラーがでなければ起動しましょう!
$ sudo hostapd start
これで一先ずAP化することはできました。
あとは、無線LANクライアントをインターネットに接続するための設定をすることで、無線LANルータとして使用できます!<追記>
hostapdを自動起動するには、/etc/init.d/hostapd に DAEMON_CONF=/etc/hostapd/hostapd を設定すれば良いです。
(デフォルトでは、DAEMON_CONFには何も設定されてません)
以下を参照しました。unix.stackexchange.com
そのためのDHCPサーバの設定や、NATの設定は以下で書いてますので参照ください。
UbuntuでNATを有効にしてルータ化する - maruchan_shiro123’s blog
ubuntu で dhcp-server を構築 - maruchan_shiro123’s blog
それにしても、アクセスポイント買わなくてLinuxでまかなえちゃうとは。。
それにwiresharkをインストールすれば、無線LANのパケットも見えて、勉強にもなるし。。!
ありがたや〜
ubuntu で dhcp-server を構築
環境
Ubuntu 14.04.2 LTS
構築手順
1.パッケージのインストール
$ sudo apg-get install isc-dhcp-server
2.DHCPサーバを有効にするインタフェースを指定
$ sudo vi /etc/default/isc-dhcp-server INTERFACES="eth2"
※eth2でDHCPサーバが動作
3.DHCPサーバの設定ファイルを編集
$ sudo vi /etc/dhcp/dhcpd.conf subnet 192.168.10.0 netmask 255.255.255.0 { range 192.168.10.10 192.168.10.30; option domain-name-servers 8.8.8.8, 8.8.4.4; option routers 192.168.10.1; option subnet-mask 255.255.255.0; option broadcast-address 192.168.10.255; default-lease-time 600; max-lease-time 7200; }
※option domain-name-serverでDNSサーバを指定
※option routersでデフォルトルータを指定
4.DHCPサーバを有効にするインタフェースにアドレスを設定
Network-Managerが有効な場合、GUIからネットワークインタフェースを追加
今回は、eth2を追加し、192.168.10.1/24 のアドレスを設定
Network-Managerを再起動するコマンド
$sudo restart network-manager
5.DHCPサーバを開始する
sudo initctl start isc-dhcp-server
ここ、ハマりました。。
initctlコマンドでDHCPサーバを起動するようです
参考にしたサイト
まさおのブログ (表): Ubuntu で DHCP サーバ
日本語man page を一時的に英語で表示
環境変数LANG を変更するだけでok
変更前
$ echo $LANG ja_JP.UTF-8
上記を以下のように変更します
LANG=C export LANG
これで、manを表示すれば英語になっているはず
また、元に戻すときは以下のようにします
export LANG='ja_JP.UTF-8'
参考サイト
UbuntuTips/Others/MessagesInEnglish - Ubuntu Japanese Wiki
manコマンドの日本語化と、一時的に英語に戻す方法 - progd
起動時からLANG=Cを読み込む場合は以下のようにする
#LANG=ja_JP.UTF-8 #=>コメントアウト LANG=C #=>追記
以下を参考にしました
LinuxのUbuntuやDebianで起動時にLANG=Cを実行する方法・コマンド - MiuxMiu
ubuntu に nkf をインストール
Windows XP だった デスクトップに Lubuntu を入れてルンルンです。
やっぱりLubuntuは軽い!Ubuntu は PC のスペック的に重くて使えない感じでした。
そこでこれからガンガンLubuntu を使うために、色々と必要なパッケージをインストールしています。
今回は nkf のインストール手順を記載。(まぁ、apt-getコマンドですぐインストールできるんですが。。)
<インストール手順>
sudo apt-get install nkf
※パッケージの情報表示コマンド
- apt-cache search nkf で利用可能なパッケージを表示
- apt-cache showpkg nkf でパッケージの情報を表示
- apt-cache show nkf でパッケージレコードを表示
<文字コード変換>
Windows環境で作成した 文字コード:SJIS, 改行コード:CR+LFのファイルを
Linux環境用に 文字コード:UTF-8, 改行コード:LF に変換します
nkf --overwrite -w -Lu [textfile]
[参照URL]
UbuntuTips/FileHandling/ConvertTextfileCharacterEncoding - Ubuntu Japanese Wiki
NTP で時刻合わせ | 自宅サーバー Debian/Ubuntu
ntp自体の仕様も知らないとね
NTPとWindows時刻同期サービス − @IT
自作の Picture Dictionary を作ろう!
今まで、分からない英単語はipadの Longman Advanced American Dictionary で調べて、それをEvernoteでエクスポートしてました。そしてEvernoteでhtmlに変換してエクスポートして、会社とかの隙間時間に見る、といったことをしてました。
これも悪くは無いんですけど、さらに効率化できる方法を思いつきました。
それは、google でその単語の image を調べて、画像もその辞書に張れば良い、ということです!
日本語と英語では、概念が違うから、日本語の社会で作られた概念と照らし合わせて理解しようとすると、意味が違ってくることがあります。
それを補正する方法でもありますし、最初にその単語を画像でイメージできることで、意味がすんなり入ってくるようになります。
また、単語は、定義を覚えようとするのではなく、例文からだけで意味を掴もうとするほうが、実践的です。
日本語も、会話や状況の中で、ある単語の使われ方、というのは覚えていっているわけなので。
ここでは、自作のPicture Dictionary を作るためのスクリプトを公開します。
ただ、自分の環境に合わせた作りなので、単純にダウンロードして実行しても動かないかもしれません。
ご自信の環境に合わせて、カスタマイズしていただければと思います。
手順
①ipadのLongman Advanced American Dictionary で、単語を調べて、Evernoteにエクスポートします。
②Evernoteから、そのノートをhtmlに変換してエクスポートします。
③ ②でエクスポートした単語の一覧を作成(filelist.txtに出力)します。
③ ③で作成した単語のimageをwebで検索し、画像を保存します。
⑤その画像を②のhtmlに挿入します。
手順はここまで。
①、②は手動ですが③~⑤は自動化してます。
以下がスクリプトです。
use strict; use warnings; use diagnostics; use Encode qw(decode); # ③検索単語をファイルに抽出 sub create_filelist { # my $file=shift; my $file='filelist.txt'; open (FH, ">", $file) or die $!; foreach my $html (glob "../20150315/*.html"){ # print $html, "\n"; if($html =~ /LAAD .+ (\w+)( \(\w+\))?.html/){ print $1, "\n"; print FH $1, "\n"; } } close FH; } # ⑤HTMLにimageを挿入 sub rename_filename{ my @data = (); my $word; foreach my $html (glob "../20150315/*.html"){ if($html =~ /LAAD .+ (\w+)( \(\w+\))?.html/){ print $1, "\n"; $word=$1; print $html; open(FH, $html) or die $!; while(<FH>){ if (/<span style="display: block"><\/span>/){ push(@data, $_); #<img src="apple - Google Search - Internet Explorer.jpg"> push(@data, "<img src=\"image\\$word - Google Search - Internet Explorer.jpg\">"); next; } else{ push(@data, $_); } } close FH; open(OUT, ">", $html) or die $!; print @data; print OUT @data; close OUT; } } } # 適宜コメントアウト/解除 &create_filelist(); #&rename_filename();
//④単語に関する画像を取得 URL="https://www.google.co.jp/search?q=photo&source=lnms&tbm=isch&sa=X&ei=8oInVJSbCsWl8AWIqYDgBg&ved=0CAgQ_AUoAQ&biw=1536&bih=860#tbm=isch&q=" //IEを起動し、指定のURLへ移動 IE = CREATEOLEOBJ("InternetExplorer.Application") IE.visible = True //検索語一覧ファイル file="filelist.txt" fid=fopen(file, F_READ) //ファイル名に空行が含まれる前までが検索対象 i=1 while true word=fget(fid,i) ifb word <> "" then print word //英単語を検索 IE.navigate(URL+word) //ウインドウが処理可能な状態になるまで待機 REPEAT SLEEP(0.1) UNTIL !IE.BUSY AND IE.readystate = 4 sleep(2) //アクティブウインドウの画像を保存 id=getid("Google Search - Internet Explorer") titl=status(id, ST_TITLE) if titl <> "" then SAVEIMG("image\"+titl, id, , , , , , 50) else break endif i=i+1 wend
手動でやると、300個くらいの単語をPicture Dictionry にするには、2, 3 時間かかるので、自動化は必須ですね。
ミニマルPerl のメモ
catと同様の動作をする
$ perl -w -e 'while(<>) { print; }' file file2
abc
def
$ perl -wnl -e 'print;' file file2
abc
def
$ perl -wpl -e '' file file2
abc
def
#---
perlの重要な起動オプション(P16)
- e
- w
- n
- p
- l
- 0
#---
perlの起動のオプション詳細
- n: 入力を処理する
$ sed 's/^/ /g' file
123
456
perlで表すと以下
$ perl -wnl -e 's/^/ /g; print;' file
123
456
- p: 自動出力
$ perl -wpl -e 's/^/ /g;' file
123
456
- l: 行末を処理
$ perl -wn -e 'print $.;' three_line_file
123
- lオプションを省略すると、改行が付与されない
$ perl -wnl -e 'print $.;' three_line_file
1
2
3
- lオプションを使わないで同じことを実行
$ perl -wn -e 'print $., "\n";' three_line_file
1
2
3
#---
入力レコードセパレータの変更
デフォルト
レコードが行単位
$ perl -wpl -e 's/^/ /g;' memo
This is the file "memo", which has these
lines spread out like so.
And then if continues to a
second paragraph.
ファイル全体が1つのレコード
$ perl -0777 -wpl -e 's/^/ /g;' memo
This is the file "memo", which has these
lines spread out like so.
And then if continues to a
second paragraph.
本当は、段落がレコード?
$ perl -00 -wpl -e 's/^/ /g;' memo
This is the file "memo", which has these
lines spread out like so.
And then if continues to a
second paragraph.
入力レコードセパレータの特殊文字:$/
#---
特殊変数
$_
最後に読み込んだ入力レコード
$.
現在の行番号
$ perl -wnl -e 'printf "$.: "; print;' file
1: 123
2: 456
1つのprintだけを使う場合
$ perl -wnl -e 'print "$.: $_";' file
1: 123
2: 456
#---
モジュールをロードする
$ perl -M'Text::Autoformat' -00 -wn -e 'print autoformat "$.: $_", { right => 60 };' memo
#---
ワンライナーバージョンをPerlスクリプトで記述
$ perl -wnl -e 'print;' file
123
456
$ ./perl_cat file
123
456
$ cat perl_cat
#!/usr/bin/perl -wnl
print;
#---
バックスラッシュ
$ perl test.pl
Spendy's restaurant saves you $$$
Haru@Haru-PC ~/perl
$ cat test.pl
#!/usr/bin/perl
print 'Spendy\'s restaurant saves you $$$';
→ネストしたシングルクォートをリテラル文字として扱う
#---
perldebugの使い方
●変数に値を設定して表示($xxx=yyy, p $xxx)
12: my $pattern;
DB<1> $pattern='perl'
DB<2> p $pattern
perl
DB<3>
●周辺のソースを表示(l, v)
DB<3> l
12==> my $pattern;
13 #print "Enter search string: ";
14 #chomp ($pattern = <> );
15: chomp ($pattern = './perl_debugger.pl' );
16: return $pattern;
17 }
18
19 # Function : find_files
20 # Description : to get list of filenames that contains the input pattern.
21 sub find_files
DB<3>
#----
DB<11> v
28
29 # taking out the filenames that contains pattern.
30: @list = grep {
31==> $file = $_;
32: open $FH,"$file";
33: @lines = <$FH>;
34: $count = grep { /$pattern/ } @lines;
35: $file if($count);
36 } @files;
37: return @list;
DB<11>
●現在のpackageの変数を表示(V)
DB<8> V
$GLOB_ALPHASORT = 8192
(略)
$GLOB_NOCHECK = 16
DB<8>
●現在読み込んでいるモジュールとバージョンを表示(M)
DB<11> M
'/usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int/auto/Term/ReadLine/Gnu/XS/autosplit.ix' => '/usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int/auto/Term/ReadLine/Gnu/XS/autosplit.ix'
'AutoLoader.pm' => '5.71 from /usr/lib/perl5/5.14/AutoLoader.pm'
'Carp.pm' => '1.20 from /usr/lib/perl5/5.14/Carp.pm'
'Config.pm' => '/usr/lib/perl5/5.14/i686-cygwin-threads-64int/Config.pm'
'Config_git.pl' => '/usr/lib/perl5/5.14/i686-cygwin-threads-64int/Config_git.pl'
'Config_heavy.pl' => '/usr/lib/perl5/5.14/i686-cygwin-threads-64int/Config_heavy.pl'
'DynaLoader.pm' => '1.13 from /usr/lib/perl5/5.14/i686-cygwin-threads-64int/DynaLoader.pm'
'Exporter.pm' => '5.64_03 from /usr/lib/perl5/5.14/Exporter.pm'
'File/Glob.pm' => '1.13 from /usr/lib/perl5/5.14/i686-cygwin-threads-64int/File/Glob.pm'
'IO.pm' => '1.25_04 from /usr/lib/perl5/5.14/i686-cygwin-threads-64int/IO.pm'
'IO/Handle.pm' => '1.31 from /usr/lib/perl5/5.14/i686-cygwin-threads-64int/IO/Handle.pm'
'SelectSaver.pm' => '1.02 from /usr/lib/perl5/5.14/SelectSaver.pm'
'Symbol.pm' => '1.07 from /usr/lib/perl5/5.14/Symbol.pm'
'Term/ReadLine.pm' => '1.07 from /usr/lib/perl5/5.14/Term/ReadLine.pm'
'Term/ReadLine/Gnu.pm' => '1.20 from /usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int/Term/ReadLine/Gnu.pm'
'Term/ReadLine/Gnu/XS.pm' => '1.17 from /usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int/Term/ReadLine/Gnu/XS.pm'
'XSLoader.pm' => '0.13 from /usr/lib/perl5/5.14/XSLoader.pm'
'dumpvar.pl' => '/usr/lib/perl5/5.14/dumpvar.pl'
'feature.pm' => '1.20 from /usr/lib/perl5/5.14/feature.pm'
'perl5db.pl' => '1.33 from /usr/lib/perl5/5.14/perl5db.pl'
'strict.pm' => '1.04 from /usr/lib/perl5/5.14/strict.pm'
'vars.pm' => '1.02 from /usr/lib/perl5/5.14/vars.pm'
'warnings.pm' => '1.12 from /usr/lib/perl5/5.14/warnings.pm'
'warnings/register.pm' => '1.02 from /usr/lib/perl5/5.14/warnings/register.pm'
DB<11>
●現在のサブルーチンをreturnまで続行(r)
DB<11> r
list context return from File::Glob::csh_glob:
0 './perl_debugger.pl'
main::find_files(perl_debugger.pl:31):
31: $file = $_;
DB<11>
●内部変数を表示(r)
DB<13> y
$file = './perl_debugger.pl'
$pattern = './perl_debugger.pl'
@files = (
0 './perl_debugger.pl'
)
@list = (
empty array
)
DB<13>
●プログラムを実行(n, s)
●配列の中身を表示(x)
DB<13> x @files
0 './perl_debugger.pl'
DB<14>
●breakpointを設定して表示(b [line], L)
DB<14> b 33
DB<15> L
perl_debugger.pl:
33: @lines = <$FH>;
break if (1)
DB<15>
●breakpoint を特定の条件の数値で指定して実行(b [line] [condition])
main::(check_breakpoint.pl:3): foreach my $i (1..100){
DB<1> v
1 #!/usr/bin/perl
2
3==> foreach my $i (1..100){
4: if($i==50) {
5: print "i=50\n";
6 }
7 }
8
DB<1> b 4 $i==50
DB<2> L
check_breakpoint.pl:
4: if($i==50) {
break if ($i==50)
DB<2> c
main::(check_breakpoint.pl:4): if($i==50) {
DB<2> s
main::(check_breakpoint.pl:5): print "i=50\n";
DB<2>
●breakpoint を特定の条件の文字列($_)で指定して実行(b [line] [condition])
DB<5> v
6 Enjoy Perl Debug!
7 END
8
9==> foreach (split(/\n/,$data)){
10: if (/test/) {
11: print $_, "\n";
12 }
13 }
DB<5> b 10 /test/ ★9行目に設定すると意図した動作とならない
DB<6> L
check_breakpoint2.pl:
10: if (/test/) {
break if (/test/)
DB<6> c
main::(check_breakpoint2.pl:10): if (/test/) {
DB<6> v
7 END
8
9: foreach (split(/\n/,$data)){
10==>b if (/test/) {
11: print $_, "\n";
12 }
13 }
DB<6> s
main::(check_breakpoint2.pl:11): print $_, "\n";
DB<6>
●breakpoint を特定の条件の文字列($str)で指定して実行(b [line] [condition])
DB<1> v
6 Enjoy Perl Debug!
7 END
8
9==> foreach my $str (split(/\n/,$data)){
10: if ($str =~ /test/) {
11: print $str, "\n";
12 }
13 }
DB<1> b 10 $str=~/test/ ★
DB<2> L
check_breakpoint3.pl:
10: if ($str =~ /test/) {
break if ($str=~/test/)
DB<2> c
main::(check_breakpoint3.pl:10): if ($str =~ /test/) {
DB<2> v
7 END
8
9: foreach my $str (split(/\n/,$data)){
10==>b if ($str =~ /test/) {
11: print $str, "\n";
12 }
13 }
DB<2> s
main::(check_breakpoint3.pl:11): print $str, "\n";
DB<2>
●デバッグを再実行(R)
●全てのbreakpointを削除(B *)
DB<1> B *
Deleting all breakpoints...
DB<2> L
DB<2>