Perlのモジュールをつかいつつ、AAで簡単にグラフを書く

CPANでGraph::Easyをinstall

$ cpanm Graph::Easy
--> Working on Graph::Easy
Fetching
http://search.cpan.org/CPAN/authors/id/S/SH/SHLOMIF/Graph-Easy-0.71.tar.gz ...
OK
Configuring Graph-Easy-0.71 ... OK
Building and testing Graph-Easy-0.71 ... OK
Successfully installed Graph-Easy-0.71
1 distribution installed

直接出力(集約)

$ graph-easy <<<'[R1],[R2] --> [R3]-->[R4]'
+----+     +----+     +----+
| R1 | --> | R3 | --> | R4 |
+----+     +----+     +----+
             ^
             |
             |
           +----+
           | R2 |
           +----+

直接出力(拡散)

$ graph-easy <<<'[R1]-->[R2],[R3],[R4]'
+----+     +----+     +----+
| R4 | <-- | R1 | --> | R3 |
+----+     +----+     +----+
             |
             |
             v
           +----+
           | R2 |
           +----+

外部ファイルを読み込んで出力

$ cat topology.txt
[R1] -- lan1 --> [R2]
[R1] -- lan2 --> [R3]
[R3] --> [R4]
[R2] --> [R4]

$ graph-easy topology.txt
+-------+  lan2   +----+     +----+
|  R1   | ------> | R3 | --> | R4 |
+-------+         +----+     +----+
  |                            ^
  | lan1                       |
  v                            |
+-------+                      |
|  R2   | ---------------------+
+-------+

Graph::Easy - Manual - Syntax
Graph::Easy::Parser - Parse Graph::Easy from textual description - metacpan.org

nmapについて

nmapは管理下のネットワークを対象にして使用しましょう

  • 概要(nmapとは?)

ネットワーク調査ツールおよびセキュリティ/ポートスキャナ(man nmapより)

  • 書式

nmap [<スキャンタイプ>] [<オプション>] [<ターゲット>]

  • オプション(man コマンドを成型しただけ。詳細は後程。。)
    • スキャンタイプ
      • -sS
      • -sT
      • -sF
      • -sX
      • -sN
      • -sP
      • -sV
      • -sU
      • -sO
      • -sI
      • -sA
      • -sW
      • -sR
      • -sL
      • -b
    • オプション
      • -P0
      • -PA [portlist]
      • -PS [portlist]
      • -PU [portlist]
      • -PE
      • -PP
      • -PM
      • -PB
      • -O
      • --osscan_limit
      • -A
      • -f
      • -v
      • -h
      • -oN
      • -oX
      • -oG
      • -oA
      • -oS
      • --resume
      • --exclude
      • --excludefile
      • --append_output
      • -iL
      • -iR
      • -p
      • -F Fast scan mode.
      • -D
      • -S
      • -e
      • --source_port
      • --data_length
      • -n
      • -R
      • -r
      • --ttl
      • --randomize_hosts
      • -M
      • --packet_trace
      • --datadir [directoryname]
      • -T
      • --host_timeout
      • --max_rtt_timeout
      • --min_rtt_timeout
      • --initial_rtt_timeout
      • --max_hostgroup
      • --min_hostgroup
      • --max_parallelism
      • --min_parallelism
      • --scan_delay
  • 参考

清く、正しい、nmapの使い方
Nmap リファレンスガイド (Man Page) |

  • 成型方法
$ man nmap | col -bfx > tmp.txt
$ cat tmp.txt | egrep "\W\W\W+\-{1,2}[A-z]" 
その後、オプション行を精査

layer8.sh

ping新発見。。

pingIPv4アドレスの"xxx.xxx.xxx.xxx"という見慣れた表記以外にも、
32ビットのIPv4アドレスをそのまま10進数にしたドットで区切らない数字の表記に宛ててもPingが打てる!

  • 通常の表記
  ping 127.0.0.1
  • 32ビットをそのまま10進数にした表記
  ping 2130706433
    • (127*256^3)+(0*256^2)+(0*256^1)+(1*256^0) = 2130706433

perlで簡単に計算ツールを作った。

#!/usr/bin/env perl
use strict;
use warnings;
my $ip =$ARGV[0];
my @ip = split /\./, $ip;
print $ip[0] * 256**3 + $ip[1] * 256**2 + $ip[2] * 256**1 + $ip[3], "\n";

Pingの結果は以下のとおり。。

$ ping -c 5 `perl ipaddr_03.pl  127.0.0.1`
PING 2130706433 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.017 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.050 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.035 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.032 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.032 ms

--- 2130706433 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.017/0.033/0.050/0.011 ms

へぇぇぇぇ、っていうだけのおはなし。。

参考サイト

IPv4

IPv4ヘッダ

    0                   1                   2                   3   
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |Version|  IHL  |Type of Service|          Total Length         |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |         Identification        |Flags|      Fragment Offset    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |  Time to Live |    Protocol   |         Header Checksum       |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                       Source Address                          |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    Destination Address                        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                    Options                    |    Padding    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
フィールド名 フィールド名(日本語) ビット長 各フィールドの説明 各フィールドの説明(日本語)
Version バージョン 4 bits - IPヘッダのバージョン番号の情報。
ここでは「4(0100)」の値が入る。
IHL ヘッダ長 4 bits IHL(Internet Header Length) IPヘッダの長さの情報。
32ビット単位。オプションを使用しないIPパケットの場合「5」。
(32bit×5= 160bit = 20byte)
Type of Service サービスタイプ 8 bits - IPパケットの優先順位の情報。
いわゆるQoS処理。
Total Length パケット長 16 bits - IPヘッダとデータを含めたパケット全体の長さ。
Identification 識別番号 16 bits - 個々のパケットを識別するための情報。
パケットが分割された時に分割されたパケットには同じ識別番号にする。
識別番号に基づき正しく組み立て処理できる。
Flags フラグ 3 bits - パケット分割における制御の情報。(詳細は別掲。)
Flagment Offset フラグメントオフセット 13 bits - フラグメントされたパケットがもとのパケットのどの位置であったかを示す情報。
Time to Live(TTL) 生存時間 8 bits - パケットの生存時間を示す情報。
実際には、何台のルータ or L3スイッチを通過することができるのかという情報。
1台のルータを通過するごとにTTL値は「 1 」つずつ減らされて、TTL値が 「 0 」 になると、パケットは破棄される。
Protocol プロトコル 8 bits - 上位層(トランスポート層)のプロトコルが何であるのかを示す情報。
(上位層プロトコルTCPを使用する場合、このプロトコル番号は「6」)
(Linuxなどの「/etc/protocols」で確認できる。)
Header Checksum ヘッダチェックサム 16 bits - IPヘッダにエラーがないかをチェックするためのチェックサム情報
Source Address 送信元アドレス 32 bits The source address. -
Destination Address 宛先アドレス 32 bits The destination address. -
Options オプション Variables(可変長) - デバックやテストを行う際に使用される情報。
Padding パディング Variables(可変長) - 上記のオプションを使用した場合にはIPヘッダ長が32ビットの整数倍にならない場合がある。
32ビットの整数倍にするために詰め物(パディング)として空データの「 0 」 の値を入れることにより調整する。