1. ホーム
  2. スクリプト・コラム
  3. パール

dig と nali を使って DNS 解決アドレスが一貫しているかどうかを判断する Perl スクリプトです。

2022-01-28 13:13:31

naliの小さなオープンソースプログラムはこちらです。http://code.google.com/p/qqwry/。

以下の文章は、プロジェクトリーダーのホームページから引用したものです。

コピーコード コードは以下の通りです。

Download

nali-0.2.tar.gz - released 2011-09-11 (download link one, download link two)
nali-0.1.tar.gz - released 2009-08-16

Description

nali, named after the Chinese pinyin for "where", contains a set of command-line programs whose main function is to take the IP strings output by some network tools and append geolocation information (using the pure database QQWry.Dat). For example, 218.65.137.1 will become 218.65.137.1 [Nanning, Guangxi Telecom]. The query is done locally and no networking is done, so there is little impact on the efficiency of the original command.

The following commands are currently included.
nali
nali-dig
nali-nslookup
nali-traceroute
nali-tracepath
nali-ping

The prerequisite for using these commands is that their corresponding commands must exist. For example, if you want to use nali-dig, you must ensure that dig exists. Their usage is the same as the original command. nali-dig, for example, is used in the same way as dig. (nali-dig is equivalent to dig |nali)

You may have noticed the command nali, which appends geographic information to the standard output IP string. the nali-* family of tools is based on this.

If you find typing nali-xxx cumbersome, then you can do some alias, for example
surfchen@mac:~$ alias traceroute='nali-traceroute'
surfchen@mac:~$ alias dig='nali-dig'

If you are using a network tool that is not included in the nali package, then you can do this.
surfchen@mac:~$ my_network_tool|nali
Server 115.168.51.180[China Telecom CDMA]
That is, nali is a command that allows you to append geographic information to the standard output ip. Similarly, if you don't like to use nali-dig, then you can use a command like dig ip|nali.

Of course, you can also use nali directly to query IP address information: the
surfchen@mac:~$ nali 222.217.167.105
222.217.167.105 [Nanning, Guangxi Telecom]

Installation

. /configure
make
[sudo] make install

Update the IP database

The IP database can be updated with the nali-update command

Develop

svn co http://qqwry.googlecode.com/svn/trunk/nali/ nali
Note that svn does not contain QQWry.Dat, so if you need to compile from the svn version, then please download QQWry.Dat yourself and put it in the share directory of your project.
Bug submission: http://code.google.com/p/qqwry/issues/list
Example

Example

There are 3 examples below.
chenze@osx:~$ nali-traceroute www.travel-web.com.tw
traceroute to ns806.travel-web.com.tw (219.87.177.148[Taiwan Province Taiwan DaBu]), 64 hops max, 40 byte packets
1 192.168.0.1 [LAN The other party is on the same intranet as you] (192.168.0.1 [LAN The other party is on the same intranet as you]) 0.747 ms 0.353 ms 0.278 ms
2 115.168.51.180 [China Telecom CDMA] (115.168.51.180 [China Telecom CDMA]) 435.595 ms 65.757 ms 48.906 ms
3 115.168.51.161 [China Telecom CDMA] (115.168.51.161 [China Telecom CDMA]) 70.990 ms 66.751 ms 46.936 ms
4 115.168.51.17 [China Telecom CDMA] (115.168.51.17 [China Telecom CDMA]) 192.944 ms 72.679 ms 46.958 ms
5 222.217.167.105 [Guangxi Nanning Telecom] (222.217.167.105 [Guangxi Nanning Telecom]) 66.963 ms 54.412 ms 54.943 ms
6 218.65.137.1 [Guangxi Nanning Telecom] (218.65.137.1 [Guangxi Nanning Telecom]) 102.969 ms 73.220 ms 47.016 ms
7 202.97.21.165 [Guangxi Telecom Backbone] (202.97.21.165 [Guangxi Telecom Backbone]) 432.915 ms 161.390 ms 165.018 ms
8 * 202.97.40.225 [China Telecom Backbone] (202.97.40.225 [China Telecom Backbone]) 185.598 ms 161.236 ms
9 202.97.33.202 [Shanghai Telecom Backbone International Exit] (202.97.33.202 [Shanghai Telecom Backbone International Exit]) 79.857 ms 66.537 ms

良い仕事をしようと思えば、良い仕事をしなければなりません。ツールはあります。ここに我々のニーズがあります。31のDNSアドレスを持つドメインのバッチがあり、それらをローテーションして、31のDNSすべてで同じ解決をするかどうかを確認し、解決をする場合は、別のファイルに入力したい。これがそのスクリプトである。

コピーコード コードは以下の通りです。

#! /usr/bin/perl
use strict;

open DNS, "DNS_IP.txt" or die "i can't filnd the file1!\n";;
open URL, "url_jiangsu.txt" or die "i can't filnd the file!\n";;
open NUM, ">>numbers.txt";
open URLS,">>url_in_jiangsu.txt";
while( my $url=<URL>){
chomp $url;
my $num_1=0;
my $all=0;
$num_1='/usr/bin/dig \@221.131.143.69 $url +tries=1 +time=3 +short|grep -v '[a-z]. *'|head -1|nali|grep -q 'Jiangsu. *move' && echo 1||echo 0′;#Note that the first and last single quote here is actually the one above the tab key
while (my $dns=<DNS>){
chomp $dns;
my $num='/usr/bin/dig \@$dns $url +tries=1 +time=3 +short|grep -v '[a-z]. *'|head -1|nali|grep -q 'move' && echo 1||echo 0′;#Note that the first and last single quote here is actually the one above the tab key
$all+=$num;
}
if($all == 31 and $num_1==1){
print URLS $url."\n";
}
print NUM $url." ". $all."\n";
seek( DNS, 1, 0 );

}
close DNS;
close URL;
close URLS;
close NUM;