Whois.pl: Skirtumas tarp puslapio versijų
Jump to navigation
Jump to search
117 eilutė: | 117 eilutė: | ||
print "Whois lookup completed. Results saved to $output_file\n"; | print "Whois lookup completed. Results saved to $output_file\n"; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | V3 subnet isskaidymas ir tikrinimas po viena ip, taip pat rdns irasymas | ||
+ | |||
+ | <syntaxhighlight lang="perl"> | ||
+ | #!/usr/bin/perl | ||
+ | # sudo apt install libnet-whois-ip-perl libtext-csv-perl libnet-cidr-perl libnet-cidr-lite-perl libnetaddr-ip-perl | ||
+ | |||
+ | use strict; | ||
+ | use warnings; | ||
+ | use Net::Whois::IP qw(whoisip_query); | ||
+ | use Text::CSV; | ||
+ | use Data::Dumper; | ||
+ | use NetAddr::IP; | ||
+ | use Socket; | ||
+ | |||
+ | # Input and output files | ||
+ | my $input_file = "ips.txt"; | ||
+ | my $output_file = "whois_results.csv"; | ||
+ | |||
+ | # Open input file | ||
+ | open(my $fh, '<', $input_file) or die "Cannot open $input_file: $!"; | ||
+ | |||
+ | # Open output CSV file | ||
+ | my $csv = Text::CSV->new({ binary => 1, eol => "\n" }); | ||
+ | open(my $out_fh, '>', $output_file) or die "Cannot open $output_file: $!"; | ||
+ | $csv->print($out_fh, ["IP", "RDNS", "Country", "Org"]); | ||
+ | |||
+ | # Function to extract organization-related fields | ||
+ | sub extract_org_info { | ||
+ | my ($whois) = @_; | ||
+ | my @org_fields; | ||
+ | |||
+ | foreach my $key (keys %$whois) { | ||
+ | next if ($key =~ /(phone|abuse|OrgTechRef)/i); | ||
+ | if ($key =~ /org/i) { | ||
+ | push @org_fields, "$key: " . ($whois->{$key} // "Unknown") if defined($whois->{$key}); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return join(" ", @org_fields) || "Unknown"; | ||
+ | } | ||
+ | |||
+ | sub make_ip_iterator { | ||
+ | my $ip = shift; | ||
+ | |||
+ | my $mask = NetAddr::IP->new($ip); | ||
+ | |||
+ | my $i = 0; | ||
+ | return sub { | ||
+ | return $mask->nth($i++); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | # Process each line | ||
+ | while (my $line = <$fh>) { | ||
+ | chomp $line; | ||
+ | |||
+ | my @ips; | ||
+ | if ($line =~ /\//) { | ||
+ | my $iterator = make_ip_iterator($line); | ||
+ | while (my $ip = $iterator->()) { | ||
+ | if ($ip =~ m{^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)}) { | ||
+ | push @ips, $1; | ||
+ | } | ||
+ | } | ||
+ | } else { | ||
+ | push @ips, $line; | ||
+ | } | ||
+ | foreach my $ip (@ips) { | ||
+ | print "Processing: $ip\n"; | ||
+ | my $packed_ip = inet_aton($ip); | ||
+ | my $hostname = gethostbyaddr($packed_ip, AF_INET); | ||
+ | # Perform whois lookup | ||
+ | my $whois = whoisip_query($ip); | ||
+ | my $country = $whois->{country} // "Unknown"; | ||
+ | # Extract organization information | ||
+ | my $org_info = extract_org_info($whois); | ||
+ | # Write to CSV | ||
+ | $csv->print($out_fh, [$ip, $hostname, $country, $org_info]); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | # Close files | ||
+ | close $fh; | ||
+ | close $out_fh; | ||
+ | |||
+ | print "Whois lookup completed. Results saved to $output_file\n"; | ||
+ | </syntaxhighlight> | ||
+ | |||
[[Category:Scripts]] | [[Category:Scripts]] |
Dabartinė 15:28, 25 vasario 2025 versija
Daro whois surašytiems į ips.txt ip adresams ir subnetams, rezultatus surašo į whois_results.csv
#!/usr/bin/perl
# sudo apt install libnet-whois-ip-perl libtext-csv-perl
use strict;
use warnings;
use Net::Whois::IP qw(whoisip_query);
use Text::CSV;
use Data::Dumper;
# Input and output files
my $input_file = "ips.txt";
my $output_file = "whois_results.csv";
# Open input file
open(my $fh, '<', $input_file) or die "Cannot open $input_file: $!";
# Open output CSV file
my $csv = Text::CSV->new({ binary => 1, eol => "\n" });
open(my $out_fh, '>', $output_file) or die "Cannot open $output_file: $!";
$csv->print($out_fh, ["IP", "Country", "Org-Name"]);
# Process each line
while (my $line = <$fh>) {
chomp $line;
# Extract IP address from CIDR notation if present
if ($line =~ m{^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)}) {
my $ip = $1;
print "Processing: $ip\n";
# Perform whois lookup
my $whois = whoisip_query($ip);
print Dumper($whois);
my $country = $whois->{Country} // "Unknown";
my $org_name = $whois->{Organization} // $whois->{org} // "Unknown";
my $person = $whois->{Person};
# Write to CSV
$csv->print($out_fh, [$line, $country, $org_name, $person]);
}
}
# Close files
close $fh;
close $out_fh;
print "Whois lookup completed. Results saved to $output_file\n";
V2 traukia tiktai organizacijas.
#!/usr/bin/perl
# sudo apt install libnet-whois-ip-perl libtext-csv-perl
use strict;
use warnings;
use Net::Whois::IP qw(whoisip_query);
use Text::CSV;
use Data::Dumper;
# Input and output files
my $input_file = "ips.txt";
my $output_file = "whois_results.csv";
# Open input file
open(my $fh, '<', $input_file) or die "Cannot open $input_file: $!";
# Open output CSV file
my $csv = Text::CSV->new({ binary => 1, eol => "\n" });
open(my $out_fh, '>', $output_file) or die "Cannot open $output_file: $!";
$csv->print($out_fh, ["IP", "Country", "Org"]);
# Function to extract organization-related fields
sub extract_org_info {
my ($whois) = @_;
my @org_fields;
foreach my $key (keys %$whois) {
next if ($key =~ /(phone|abuse|OrgTechRef)/i);
if ($key =~ /org/i) {
push @org_fields, "$key: " . ($whois->{$key} // "Unknown") if defined($whois->{$key});
}
}
return join(" ", @org_fields) || "Unknown";
}
# Process each line
while (my $line = <$fh>) {
chomp $line;
# Extract IP address from CIDR notation if present
if ($line =~ m{^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)}) {
my $ip = $1;
print "Processing: $ip\n";
# Perform whois lookup
my $whois = whoisip_query($ip);
my $country = $whois->{country} // "Unknown";
# Extract organization information
my $org_info = extract_org_info($whois);
# Write to CSV
$csv->print($out_fh, [$ip, $country, $org_info]);
}
}
# Close files
close $fh;
close $out_fh;
print "Whois lookup completed. Results saved to $output_file\n";
V3 subnet isskaidymas ir tikrinimas po viena ip, taip pat rdns irasymas
#!/usr/bin/perl
# sudo apt install libnet-whois-ip-perl libtext-csv-perl libnet-cidr-perl libnet-cidr-lite-perl libnetaddr-ip-perl
use strict;
use warnings;
use Net::Whois::IP qw(whoisip_query);
use Text::CSV;
use Data::Dumper;
use NetAddr::IP;
use Socket;
# Input and output files
my $input_file = "ips.txt";
my $output_file = "whois_results.csv";
# Open input file
open(my $fh, '<', $input_file) or die "Cannot open $input_file: $!";
# Open output CSV file
my $csv = Text::CSV->new({ binary => 1, eol => "\n" });
open(my $out_fh, '>', $output_file) or die "Cannot open $output_file: $!";
$csv->print($out_fh, ["IP", "RDNS", "Country", "Org"]);
# Function to extract organization-related fields
sub extract_org_info {
my ($whois) = @_;
my @org_fields;
foreach my $key (keys %$whois) {
next if ($key =~ /(phone|abuse|OrgTechRef)/i);
if ($key =~ /org/i) {
push @org_fields, "$key: " . ($whois->{$key} // "Unknown") if defined($whois->{$key});
}
}
return join(" ", @org_fields) || "Unknown";
}
sub make_ip_iterator {
my $ip = shift;
my $mask = NetAddr::IP->new($ip);
my $i = 0;
return sub {
return $mask->nth($i++);
}
}
# Process each line
while (my $line = <$fh>) {
chomp $line;
my @ips;
if ($line =~ /\//) {
my $iterator = make_ip_iterator($line);
while (my $ip = $iterator->()) {
if ($ip =~ m{^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)}) {
push @ips, $1;
}
}
} else {
push @ips, $line;
}
foreach my $ip (@ips) {
print "Processing: $ip\n";
my $packed_ip = inet_aton($ip);
my $hostname = gethostbyaddr($packed_ip, AF_INET);
# Perform whois lookup
my $whois = whoisip_query($ip);
my $country = $whois->{country} // "Unknown";
# Extract organization information
my $org_info = extract_org_info($whois);
# Write to CSV
$csv->print($out_fh, [$ip, $hostname, $country, $org_info]);
}
}
# Close files
close $fh;
close $out_fh;
print "Whois lookup completed. Results saved to $output_file\n";