セキスペの過去問を解いていたらポートスキャンに関する問題が出てきた。
synを送ってその反応を見る、というもので、
まず「それを何というか」という問題があり、「ポートスキャン」と回答したが、
正解は「SYNスキャン」であった。
SYNスキャンはポートスキャンの一種なので間違いではないが、
SYNだけ送って、そのあとSYNACKが返ってきてもセッションを確立しないので、
スキャン先に接続履歴を残したくないときに使うそうだ。
もう一つの問題は、「ポートが閉じているときにどういう反応があるか」というもので、
私は「応答なし」と答えたのだが正解は「RSTACK受信」および「応答なし」であった。
私は応答がないと思い込んでいたので、えっと思って
パソコンでwiresharkを起動して自分のサーバへのアクセスで試してみた。
接続できないはずのtelnetアクセスをしてみると応答がない。
しかしそれはポートが開いてるかどうか以前にiptablesで許可していないからだと気づき、
一時的にiptablesを無効にして、再度telnetしてみた。
RST,ACKが返ってくる。
なるほど。
以前nmapでポートスキャンしたときに、「ポートにアクセスできないがフィルターされているかもしれない」みたいな結果が出たことがあった。
これはsynに応答がなかった場合であろう。
サーバでtelnetサービスが動いていてもiptablesとかその前のFW装置で許可されていなければ応答が返ってこない。
だから応答が返ってこない場合はポートが開いているか閉じているかはわからない。
今書いていて思ったのだが、ポートが開いていないときにRSTを返さないような設定ができるんじゃないだろうか?
できないか?
まあいい。ふつうはRST ACKが返るということがわかった。
ところで、「ポートが開いている」という言い方をよくするが、
私はまだ若いころ、その確認方法がよくわからなかった。
どこかに設定ファイルがあって、開けるポート番号または閉じるポート番号を指定してあるのだと思っていた。
しかし、サーバ(RedHat9)設定のどこを探してもそのような設定はない。
そのサーバではiptablesは設定していなかった。設定方法も知らなかった。
検証環境のサーバだからだ。
調べていくうちにiptablesのこともわかってきたのだが、
iptablesは確かに通信を許可するポートを開けたり閉めたりするが、
いわゆる「ポートが開いている」というのはそのことを言うのではない。
まあ、ユーザや運用管理者にとっては「FWで閉じている=閉じている」
ということでよいだろう。
しかし、「FWで開いている=開いている」にはならない。
というか、そもそも「ポートが開いている」という言い方が不正確で誤解を生む。
開いているという言い方だとFWで開け閉めするのを想像するが、
正確には「そのポートをリッスンしているサービスが稼働している」
という状態である。
たとえばtelnetサービスを有効にしていてその使用ポートが23であれば、
「TCP23が開いている」となる。
使用ポートは変更できるので、telnetサービス(正確にはtelnetサーバサービス)が動いている=23番が開いているとも言えない。
そんな人はいないと思うが、telnetで80番を使うようにすることもできる(よね?)。
私のサーバではtelnetは動作していず、sshが動作していてポート番号は22でないものに変更している。
このとき、「TCP23は開いていず、SSH接続できるがTCP22は開いていない」という状態になる。
そして、iptablesでTCP23とTCP22は拒否しているので、
ポートスキャンするといずれも応答が返らない。
しかし、その結果だけからは、サーバの手前の別装置のFWやアクセスリストで拒否されているのか、
サーバのiptablesで拒否されているのか、サーバがダウンしているのか、はわからない。
アクセスしているIPアドレスが間違っている可能性もある。
pingは返ってくる、80番はアクセスできる、23番は応答がない、
であればFWかサーバのiptablesで拒否されているとわかる。
このブログを検索
2019/04/07
2019/04/06
powershellスクリプトでイベントログから勤務時間を知る
いつもイベントビューアで見ているのだが、
ちゃっとスクリプトで表示できないかなと
powershellを起動
管理者として
スクリプト実行はデフォルトで許可されていないので
Set-ExecutionPolicy RemoteSigned
y
---
$month=1
$lastday=30
$month=[int]$Args[0]
if($month -eq (1 -or 3 -or 5 -or 7 -or 8 -or 10 -or 12)){
$lastday=31
}else{
if($month -eq 2){
$lastday =28
}else{
$lastday=30
}
}
$LogName = "System"
$StartTime = New-Object System.DateTime 2019,$month,01,00,00,00,00
$EndTime = New-Object System.DateTime 2019,$month,$lastday,23,59,59,59
$EventsList = Get-WinEvent -FilterHashTable @{LogName=$LogName; StartTime = $StartTime; EndTime = $EndTime}
$EventsList = $EventsList |Where-Object {($_.Id -eq 12 -and $_.ProviderName -eq "Microsoft-Windows-Kernel-General") -or ($_.Id -eq 109)}
$EventsList | Format-Table -Property TimeCreated
---
eve.ps1 というファイル名にし、月を指定する。
実行例
PS C:\users\taro> .\eve.ps1 3
TimeCreated
-----------
2019/03/28 19:00:30
2019/03/28 19:00:09
2019/03/23 6:02:26
2019/03/23 6:02:05
2019/03/21 18:23:56
2019/03/21 18:23:31
2019/03/14 17:22:30
2019/03/14 17:22:10
2019/03/13 21:50:36
2019/03/13 21:50:16
2019/03/13 12:39:06
2019/03/13 12:38:46
2019/03/13 2:31:16
2019/03/13 2:31:00
2019/03/12 17:37:02
2019/03/12 17:36:44
2019/03/11 8:46:52
2019/03/11 8:46:32
2019/03/10 15:42:36
2019/03/10 15:42:13
2019/03/10 4:02:14
2019/03/10 4:01:50
2019/03/10 3:51:38
並び順が降順なのと、終了時間が2回出るのがアレ
月を指定しないとエラーになるのもアレ
うるう年未対応、月末日の求め方がアレ
年が固定で書いてあるのがアレ
まあ、イベントビューアを見るのとあまり変わらないけど、
PowerShellでいろいろできることがわかった。
ちゃっとスクリプトで表示できないかなと
powershellを起動
管理者として
スクリプト実行はデフォルトで許可されていないので
Set-ExecutionPolicy RemoteSigned
y
---
$month=1
$lastday=30
$month=[int]$Args[0]
if($month -eq (1 -or 3 -or 5 -or 7 -or 8 -or 10 -or 12)){
$lastday=31
}else{
if($month -eq 2){
$lastday =28
}else{
$lastday=30
}
}
$LogName = "System"
$StartTime = New-Object System.DateTime 2019,$month,01,00,00,00,00
$EndTime = New-Object System.DateTime 2019,$month,$lastday,23,59,59,59
$EventsList = Get-WinEvent -FilterHashTable @{LogName=$LogName; StartTime = $StartTime; EndTime = $EndTime}
$EventsList = $EventsList |Where-Object {($_.Id -eq 12 -and $_.ProviderName -eq "Microsoft-Windows-Kernel-General") -or ($_.Id -eq 109)}
$EventsList | Format-Table -Property TimeCreated
---
eve.ps1 というファイル名にし、月を指定する。
実行例
PS C:\users\taro> .\eve.ps1 3
TimeCreated
-----------
2019/03/28 19:00:30
2019/03/28 19:00:09
2019/03/23 6:02:26
2019/03/23 6:02:05
2019/03/21 18:23:56
2019/03/21 18:23:31
2019/03/14 17:22:30
2019/03/14 17:22:10
2019/03/13 21:50:36
2019/03/13 21:50:16
2019/03/13 12:39:06
2019/03/13 12:38:46
2019/03/13 2:31:16
2019/03/13 2:31:00
2019/03/12 17:37:02
2019/03/12 17:36:44
2019/03/11 8:46:52
2019/03/11 8:46:32
2019/03/10 15:42:36
2019/03/10 15:42:13
2019/03/10 4:02:14
2019/03/10 4:01:50
2019/03/10 3:51:38
並び順が降順なのと、終了時間が2回出るのがアレ
月を指定しないとエラーになるのもアレ
うるう年未対応、月末日の求め方がアレ
年が固定で書いてあるのがアレ
まあ、イベントビューアを見るのとあまり変わらないけど、
PowerShellでいろいろできることがわかった。
2019/03/03
python3.6のCGIでGoogleニュースのヘッドラインを抽出するスクレイピング例
python3.6によるスクレイピング例
Googleニュースのヘッドラインのタイトルを抽出する。
beautifulsoupは使わず、正規表現でゴリゴリする。
-------
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import re
import sys
import cgi
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
my_title = 'what\'s hot'
def print_head(title):
print('Content-type: text/html')
print()
print('<html><head>')
print('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">')
print('<title>'+title+'</title>')
print('</head>')
def print_tail():
print('</html>')
print_head(my_title)
print('<body>')
res = requests.get('https://news.google.com/?hl=ja&gl=JP&ceid=JP%3Aja')
res.raise_for_status()
print("From Google News JP status:" + str(res.status_code) + "<br><br>")
tmp = re.sub('\n','',res.text)
tmp = re.sub('<a href','\n<a href',tmp)
tmp = re.sub('\/a>','/a>\n',tmp)
tmplist = tmp.split('\n')
result = [ s for s in tmplist if re.match('<a href=\"\.\/articles.*?\/a>', s) or ( 'すべての記事' in s ) ]
for i in result:
if 'すべての記事' in i:
break
s = re.sub(r'<a href.*?<span >(.*?)<\/span><\/a>',r'\1',i)
print(s+"<br>")
print('</body>')
print_tail()
------
苦労したところ
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
これを入れないと、抽出した結果をprintするときに下記のようなエラーになる。
UnicodeEncodeError: 'ascii' codec can't encode characters in position 343-391: ordinal not in range(128)
googleニュースのヘッドラインだけを抽出したかったのだが、
htmlソースを見ても特定の条件がみつからない。
'<a href=\"\.\/articles.*?\/a>',
で抽出すれば見出しのリンクが取れるのだが、ヘッドライン以外もすべて取れてしまう。
「すべての記事」というキーワードが区切りになっているので、
それが出てくるまで、という条件で抽出した。
これができればどこからでもなんでも取れる....
2019/03/02
python3のhello world cgi
最小限のpython cgi
-----
#!/usr/bin/python
# -*- coding: utf-8 -*-
my_title = 'greeting from python'
my_message = 'hello, world'
###
def print_head(title):
print('Content-type: text/html')
print()
print('<html><head>')
print('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">')
print('<title>'+title+'</title>')
print('</head>')
def print_body(message):
print('<body>')
print(message)
print('</body>')
def print_tail():
print('</html>')
###
print_head(my_title)
print_body(my_message)
print_tail()
-----
#!/usr/bin/python
# -*- coding: utf-8 -*-
my_title = 'greeting from python'
my_message = 'hello, world'
###
def print_head(title):
print('Content-type: text/html')
print()
print('<html><head>')
print('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">')
print('<title>'+title+'</title>')
print('</head>')
def print_body(message):
print('<body>')
print(message)
print('</body>')
def print_tail():
print('</html>')
###
print_head(my_title)
print_body(my_message)
print_tail()
-----
3系はprintにカッコをつけてつかう
インデントでスペースとタブを混在させてはいけない
python3をデフォルトにする@centos6
google analyticsがあるcgiがinternal server errorになっていることを報告してきて、
それを直している過程で、
perl (LWP)でやっているスクレイピングが時代遅れ
pythonの2系は時代遅れ
ということを悟ったので、3系(3.6)をインストールした。
2.6とか2.7とかいろいろ入ってしまったのできれいにしようと思ったのだが、
うまく消えないのでとりあえず3系がデフォルトで動くようにした。
# pip install beautifulsoup4
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python2.7/site-packages (4.7.1)
Requirement already satisfied: soupsieve>=1.2 in /usr/local/lib/python2.7/site-packages (from beautifulsoup4) (1.8)
Requirement already satisfied: backports.functools-lru-cache; python_version < "3" in /usr/local/lib/python2.7/site-packages (from soupsieve>=1.2->beautifulsoup4) (1.5)
#
beautifulsoupなる便利なものがあると聞いて使ってみようとしたら「まだ2.7なんか使ってんのかよ」と怒られた。
# python --version
Python 2.6.6
python
とだけやると、2.6.6が起動する。
python3.6
とやれば3系が動くようにはなっているが、面倒。
# python3.6
Python 3.6.7 (default, Dec 5 2018, 15:02:16)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
"python" はシンボリックリンクなので、
それを3系にリンクしなおせばよい。
# which python
/usr/bin/python
# which python3.6
/usr/bin/python3.6
pipも
# which pip3.6
/usr/bin/pip3.6
# which pip
/usr/local/bin/pip
# ln -s /usr/bin/python3.6 /usr/bin/python
ln: creating symbolic link `/usr/bin/python': ファイルが存在します
現在のリンクを消してから3系へのリンクを作る。
# unlink /usr/bin/python
# ln -s /usr/bin/python3.6 /usr/bin/python
# ln -s /usr/bin/pip3.6 /usr/local/bin/pip
ln: creating symbolic link `/usr/local/bin/pip': ファイルが存在します
pipも同様
# unlink /usr/local/bin/pip
# ln -s /usr/bin/pip3.6 /usr/local/bin/pip
# python
Python 3.6.7 (default, Dec 5 2018, 15:02:16)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
# pip -V
pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)
pythonもpipも3系になった。
それを直している過程で、
perl (LWP)でやっているスクレイピングが時代遅れ
pythonの2系は時代遅れ
ということを悟ったので、3系(3.6)をインストールした。
2.6とか2.7とかいろいろ入ってしまったのできれいにしようと思ったのだが、
うまく消えないのでとりあえず3系がデフォルトで動くようにした。
# pip install beautifulsoup4
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python2.7/site-packages (4.7.1)
Requirement already satisfied: soupsieve>=1.2 in /usr/local/lib/python2.7/site-packages (from beautifulsoup4) (1.8)
Requirement already satisfied: backports.functools-lru-cache; python_version < "3" in /usr/local/lib/python2.7/site-packages (from soupsieve>=1.2->beautifulsoup4) (1.5)
#
beautifulsoupなる便利なものがあると聞いて使ってみようとしたら「まだ2.7なんか使ってんのかよ」と怒られた。
# python --version
Python 2.6.6
python
とだけやると、2.6.6が起動する。
python3.6
とやれば3系が動くようにはなっているが、面倒。
# python3.6
Python 3.6.7 (default, Dec 5 2018, 15:02:16)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
"python" はシンボリックリンクなので、
それを3系にリンクしなおせばよい。
# which python
/usr/bin/python
# which python3.6
/usr/bin/python3.6
pipも
# which pip3.6
/usr/bin/pip3.6
# which pip
/usr/local/bin/pip
# ln -s /usr/bin/python3.6 /usr/bin/python
ln: creating symbolic link `/usr/bin/python': ファイルが存在します
現在のリンクを消してから3系へのリンクを作る。
# unlink /usr/bin/python
# ln -s /usr/bin/python3.6 /usr/bin/python
# ln -s /usr/bin/pip3.6 /usr/local/bin/pip
ln: creating symbolic link `/usr/local/bin/pip': ファイルが存在します
pipも同様
# unlink /usr/local/bin/pip
# ln -s /usr/bin/pip3.6 /usr/local/bin/pip
# python
Python 3.6.7 (default, Dec 5 2018, 15:02:16)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
# pip -V
pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)
pythonもpipも3系になった。
2019/01/18
raspberry pi 更新
pi@raspberrypi:~$ uname -a
Linux raspberrypi 4.4.14-v7+ #895 SMP Sun Jun 26 13:59:02 BST 2016 armv7l GNU/Linux
pi@raspberrypi:~$ sudo apt-get update
Get:1 http://archive.raspberrypi.org jessie InRelease [22.9 kB]
Get:2 http://mirrordirector.raspbian.org jessie InRelease [14.9 kB]
Get:3 http://archive.raspberrypi.org jessie/main armhf Packages [171 kB]
Get:4 http://mirrordirector.raspbian.org jessie/main armhf Packages [9,539 kB]
Get:5 http://archive.raspberrypi.org jessie/ui armhf Packages [58.9 kB]
Get:6 http://mirrordirector.raspbian.org jessie/contrib armhf Packages [43.3 kB]
Get:7 http://mirrordirector.raspbian.org jessie/non-free armhf Packages [88.1 kB]
Get:8 http://mirrordirector.raspbian.org jessie/rpi armhf Packages [1,356 B]
Ign http://archive.raspberrypi.org jessie/main Translation-en_GB
Ign http://archive.raspberrypi.org jessie/main Translation-en
Ign http://archive.raspberrypi.org jessie/ui Translation-en_GB
Ign http://archive.raspberrypi.org jessie/ui Translation-en
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en
Ign http://mirrordirector.raspbian.org jessie/main Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/main Translation-en
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en
Fetched 9,939 kB in 29s (336 kB/s)
Reading package lists... Done
続いて
sudo apt-get upgrade
長い。
久しぶりにやったので。
何回か、キーボードから反応する必要がある。
sudo rpi-update
sudo reboot
sudo めんどくせーな。
reboot後
pi@raspberrypi:~$ uname -a
Linux raspberrypi 4.14.93-v7+ #1191 SMP Wed Jan 16 11:53:33 GMT 2019 armv7l GNU/Linux
Linux raspberrypi 4.4.14-v7+ #895 SMP Sun Jun 26 13:59:02 BST 2016 armv7l GNU/Linux
pi@raspberrypi:~$ sudo apt-get update
Get:1 http://archive.raspberrypi.org jessie InRelease [22.9 kB]
Get:2 http://mirrordirector.raspbian.org jessie InRelease [14.9 kB]
Get:3 http://archive.raspberrypi.org jessie/main armhf Packages [171 kB]
Get:4 http://mirrordirector.raspbian.org jessie/main armhf Packages [9,539 kB]
Get:5 http://archive.raspberrypi.org jessie/ui armhf Packages [58.9 kB]
Get:6 http://mirrordirector.raspbian.org jessie/contrib armhf Packages [43.3 kB]
Get:7 http://mirrordirector.raspbian.org jessie/non-free armhf Packages [88.1 kB]
Get:8 http://mirrordirector.raspbian.org jessie/rpi armhf Packages [1,356 B]
Ign http://archive.raspberrypi.org jessie/main Translation-en_GB
Ign http://archive.raspberrypi.org jessie/main Translation-en
Ign http://archive.raspberrypi.org jessie/ui Translation-en_GB
Ign http://archive.raspberrypi.org jessie/ui Translation-en
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en
Ign http://mirrordirector.raspbian.org jessie/main Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/main Translation-en
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en
Fetched 9,939 kB in 29s (336 kB/s)
Reading package lists... Done
続いて
sudo apt-get upgrade
長い。
久しぶりにやったので。
何回か、キーボードから反応する必要がある。
sudo rpi-update
sudo reboot
sudo めんどくせーな。
reboot後
pi@raspberrypi:~$ uname -a
Linux raspberrypi 4.14.93-v7+ #1191 SMP Wed Jan 16 11:53:33 GMT 2019 armv7l GNU/Linux
Raspberry Pi 2 Model B V1.1
コンソールケーブルをつなぐ
黒→GND
黄色→GPIO14(TXD0)
オレンジ→GPIO15(RXD0)
シリアルポートのスピードは115200
WLANの設定
pi@raspberrypi:~$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
country=JP
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
ssid="XXXXXXXXXXX"
#psk="xxxxxxxxxxxx"
psk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
pskを暗号化するコマンド
pi@raspberrypi:~$ sudo wpa_passphrase SSID password
network={
ssid="SSID"
#psk="password"
psk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
このコマンドを上記ファイルにリダイレクトすれば設定が書き込める
wlan0をdhcpにする設定
pi@raspberrypi:~$ sudo cat /etc/network/interfaces
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
以前固定IPにしていた場合、
これだけではダメで、下記ファイルも直す
pi@raspberrypi:~$ sudo cat /etc/dhcpcd.conf
hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option ntp_servers
require dhcp_server_identifier
slaac private
nohook lookup-hostname
interface wlan0
#static ip_address=192.168.0.100/24
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1
sudo ifdown wlan0
sudo ifup wlan0
をやると、IPを取る。
pi@raspberrypi:~$ sudo ifup wlan0
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/wlan0/xx:xx:xx:xx:xx:xx
Sending on LPF/wlan0/xx:xx:xx:xx:xx:xx
Sending on Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 14
DHCPREQUEST on wlan0 to 255.255.255.255 port 67
DHCPOFFER from 192.168.3.1
DHCPACK from 192.168.3.1
RTNETLINK answers: File exists
bound to 192.168.3.12 -- renewal in 37717 seconds.
pi@raspberrypi:~$
pi@raspberrypi:~$ sudo ping yahoo.com
PING yahoo.com (98.137.246.7) 56(84) bytes of data.
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (98.137.246.7): icmp_seq=1 ttl=54 time=147 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (98.137.246.7): icmp_seq=2 ttl=54 time=145 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (98.137.246.7): icmp_seq=3 ttl=54 time=145 ms
^C
--- yahoo.com ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 3004ms
rtt min/avg/max/mdev = 145.634/146.144/147.034/0.631 ms
pi@raspberrypi:~$
黒→GND
黄色→GPIO14(TXD0)
オレンジ→GPIO15(RXD0)
シリアルポートのスピードは115200
WLANの設定
pi@raspberrypi:~$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
country=JP
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
ssid="XXXXXXXXXXX"
#psk="xxxxxxxxxxxx"
psk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
pskを暗号化するコマンド
pi@raspberrypi:~$ sudo wpa_passphrase SSID password
network={
ssid="SSID"
#psk="password"
psk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
このコマンドを上記ファイルにリダイレクトすれば設定が書き込める
wlan0をdhcpにする設定
pi@raspberrypi:~$ sudo cat /etc/network/interfaces
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
以前固定IPにしていた場合、
これだけではダメで、下記ファイルも直す
pi@raspberrypi:~$ sudo cat /etc/dhcpcd.conf
hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option ntp_servers
require dhcp_server_identifier
slaac private
nohook lookup-hostname
interface wlan0
#static ip_address=192.168.0.100/24
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1
sudo ifdown wlan0
sudo ifup wlan0
をやると、IPを取る。
pi@raspberrypi:~$ sudo ifup wlan0
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/wlan0/xx:xx:xx:xx:xx:xx
Sending on LPF/wlan0/xx:xx:xx:xx:xx:xx
Sending on Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 14
DHCPREQUEST on wlan0 to 255.255.255.255 port 67
DHCPOFFER from 192.168.3.1
DHCPACK from 192.168.3.1
RTNETLINK answers: File exists
bound to 192.168.3.12 -- renewal in 37717 seconds.
pi@raspberrypi:~$
pi@raspberrypi:~$ sudo ping yahoo.com
PING yahoo.com (98.137.246.7) 56(84) bytes of data.
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (98.137.246.7): icmp_seq=1 ttl=54 time=147 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (98.137.246.7): icmp_seq=2 ttl=54 time=145 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (98.137.246.7): icmp_seq=3 ttl=54 time=145 ms
^C
--- yahoo.com ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 3004ms
rtt min/avg/max/mdev = 145.634/146.144/147.034/0.631 ms
pi@raspberrypi:~$