| 2025年11月15日 | ノート給油 |
| 2025年11月9日 | シグマ CONTEMPORARY 16-300mm F3.5-6.7 DC OS |
| 2025年9月7日 | 856.Bオーバーホール |
| 2025年9月6日 | HP35s電池交換 |
| 2025年9月3日 | PX-M730Fの黒インクカートリッジ交換 |
| 2025年7月21日 | 音声途絶 |
| 2025年7月14日 | RN-SP0002S電池交換 |
| 2025年3月18日 | emacs近代化改修 |
| 2025年2月3日 | メールが復活? |
| 2025年1月4日 | ザ・シチズン時刻合わせ |
自宅のサーバーに、けっこうアタックがある。 昔はftpdが対象だったが、 最近ではssh2でログインを試みて失敗している。 で、なぜかは知らないが中国と韓国に割り振られている IPアドレスからのことが多い。 なので、/etc/hosts.allowにこれをはじく記述を追加した。
http://cgi.apnic.net/apnic-bin/ipv4-by-country.plを使えば、 各国に割り振られたIPアドレスがすぐにわかる。 ただし、ここで得られるのはx.x.x.x/xというフォーマットのデータ。 ところが/etc/hosts.allowには x.x.x.x/x.x.x.xという形式で記述する必要がある。 これを人手でやっていたのではいやになるので、 Rubyでスクリプトを組んだ。
まず、 webブラウザで表示させたデータをコピー&ペーストでテキストファイルにする。 できたテキストファイルをこのスクリプトに喰わせると、 /etc/hosts.allowにコピーするためのテキストを標準出力に出す。
#!/usr/local/bin/ruby
# http://cgi.apnic.net/apnic-bin/ipv4-by-country.plから取得したデータで
# /etc/hosts.allow用のデータを作る
# usage: chkwd.rb src_file
#$Id: block.rb,v 1.1 2004/09/21 13:08:54 tom-a Exp tom-a $
dic = []
i = 0
begin
ARGF.each do |line|
if !(line =~ /^$/) then
dic[i] = line.scan(/[^\t\n]+/)
i += 1
end
end
dic.each do |element|
network = element[1][/[0-9.]+/]
netmask = element[1][/[0-9]+$/]
netmask2 = 0xffffffff00000000 >> netmask.to_i
d1 = (netmask2 & 0xffffffff) >> 24
d2 = (netmask2 & 0xffffff) >> 16
d3 = (netmask2 & 0xffff) >> 8
d4 = netmask2 & 0xff
printf("all : %s/%d.%d.%d.%d : deny\n",network,d1,d2,d3,d4)
end
end
#!/usr/local/bin/ruby
# http://cgi.apnic.net/apnic-bin/ipv4-by-country.plから取得したデータで
# /etc/hosts.allow用のデータを作る
# usage: chkwd.rb src_file
#$Id: block.rb,v 1.4 2004/10/01 02:43:01 tom-a Exp tom-a $
begin
ARGF.each do |line|
if !(line =~ /^$/) then
words = line.scan(/[^ \t\n]+/)
network = words[1][/[0-9.]+/]
network2 = network.scan(/[^\.]+/)
network = String.new
i = 0
while network2[i] != nil
network = network + network2[i] + "."
i += 1
end
case i
when 1
network += "0.0.0"
when 2
network += "0.0"
when 3
network += "0"
end
netmask = words[1][/[0-9]+$/]
netmask2 = 0xffffffff00000000 >> netmask.to_i
d1 = (netmask2 & 0xffffffff) >> 24
d2 = (netmask2 & 0xffffff) >> 16
d3 = (netmask2 & 0xffff) >> 8
d4 = netmask2 & 0xff
printf("all : %s/%d.%d.%d.%d : deny\n",network,d1,d2,d3,d4)
end
end
end