User:H/Range block finder.pl

This script will search all the ranges that could effect an IP looking for a block, and will report the details of that block when it finds it. This script requires perl to run and you will most likely need to install Net::Netmask.

use strict;
use LWP::UserAgent;
use Net::Netmask;
use URI::Escape;

my $ip = '<Place IP here>';
my $ua = LWP::UserAgent->new('agent' => 'Range block finder .0001b');

my @possible_masks =
(
 '255.255.255.0/24',
 '255.255.0.0/16',
 '255.0.0.0/8',
 '255.255.255.254/31',
 '255.255.255.252/30',
 '255.255.255.248/29',
 '255.255.255.240/28',
 '255.255.255.224/27',
 '255.255.255.192/26',
 '255.255.255.128/25',
 '255.255.254.0/23',
 '255.255.252.0/22',
 '255.255.248.0/21',
 '255.255.240.0/20',
 '255.255.224.0/19',
 '255.255.192.0/18',
 '255.255.128.0/17',
 '255.254.0.0/15',
 '255.252.0.0/14',
 '255.248.0.0/13',
 '255.240.0.0/12',
 '255.224.0.0/11',
 '255.192.0.0/10',
 '255.128.0.0/9',
 '254.0.0.0/7',
 '252.0.0.0/6',
 '248.0.0.0/5',
 '240.0.0.0/4',
 '224.0.0.0/3',
 '192.0.0.0/2',
 '128.0.0.0/1'
);

$ip =~ m|(\d+)\.(\d+)\.(\d+)\.(\d+)|;
my(@ip) = ($1,$2,$3,$4);

my (@masks_to_check);
push(@masks_to_check,$ip);
foreach my $mask (@possible_masks)
  {
  $mask =~ m|(\d+)\.(\d+)\.(\d+)\.(\d+)/(\d+)|;
  my(@mask_ip) = ($1,$2,$3,$4);
  my $mask = $5;
  my $count;
  my @new_ip;
  foreach my $mask_element (@mask_ip)
    {
    my $ip_element = $ip[$count];
    if ($mask_element > $ip_element)
      {
      push(@new_ip,$ip_element);
      }
    else
      {
      push(@new_ip,$mask_element);
      }
    $count++;
    }
  push(@masks_to_check,(join('.',@new_ip).'/'.$mask));
  }

foreach my $mask_to_check (@masks_to_check)
  {
  warn "Checking $mask_to_check\n";
  my $result = check_user($mask_to_check);
  if ($result)
    {
    warn
     "Block found:

      ${$result}{'user'}
      blocked by ${$result}{'blocker'}
      till ${$result}{'expiry'}(${$result}{'type'})

      ${$result}{'summary'}\n";
    last;
    }
  }

sub check_user  # Determine if the user is blocked, if so gather information about the block
  {             # and return it
  my ($user,$page) = @_;
  my $url = 'http://en.wikipedia.org/w/index.php?title=Special:Ipblocklist&ip='.uri_escape($user);
  my $data = $ua->get($url)->content(); # Get blocklist info for user
  if ($data =~ m|</a>\) blocked <a href|)       # If the user is currently blocked
    {
    # Get name of blocking admin
    ($data =~ m|\d{2}, <a href="https://dokumen123.com/en/User:(.*?)" title=|) || ($data =~ m|\d{2}, <a href="https://dokumen123.com/en//w/index\.php\?title=User:(.*?)&|); #"
    my $blocker = uri_unescape($1);
    # Get blocking summary
    ($data =~ m|<span class="comment">\((.*?)\)</span>|);
    my $comment = $1;
    # Get expiry time of block
    my $expiry;
    if ($data =~ m|expires (\d+:\d+, \d+ \D+ \d+)|)    # Match expiry time if one exists
      {
      $expiry = $1;
      }
    elsif($data =~ m|infinite|) # If there is no expiry and the word 'infinite' is found
      {
      $expiry = 'indef'; # Set to indef
      }
    # Get block type flags
    my(@flags);
    (push(@flags,'anon. only')) if ($data =~ m|anon\. only|);                   # Match anon only
    (push(@flags,'account creation blocked')) if ($data =~ m|account creation blocked|);     # Match account creation blocked
    (push(@flags,'autoblock disabled')) if ($data =~ m|autoblock disabled|);           # Match autoblock disabled
    my $block_type = ''; # Build empty string
    # If any flag exists build a flag string.
    $block_type = join(', ',@flags) if (scalar(@flags));
    return
     {
      'user'		=> $user,
      'blocker'		=> $blocker,
      'expiry'		=> $expiry,
      'type'		=> $block_type,
      'summary'		=> $comment
     }; # Queue a remove_name job to run ASAP
    }
  return 0;
  }

sub timeconv {
  my($expiry, $block_time)  = @_;
  my $duration = $expiry - $block_time;
  my $formatter = DateTime::Format::Duration->new(
    pattern => '%Y years, %m months, %e days, %H hours, %M minutes, %S seconds',
    normalize => 1,
    base => $block_time,
  );
  my %normalized = $formatter->normalize($duration);
  my @periods = ('years','months','days','hours','minutes','seconds');
  my $output;
  if ($normalized{'minutes'} || $normalized{'seconds'}) {
    $output = sprintf('until %s %s ', $expiry->ymd, $expiry->hms);
  } else {
    foreach (@periods) {
      $output .= sprintf('%s %s, ', $normalized{$_}, $_) if $normalized{$_};
      if ($normalized{$_} == 1) {
        my $singular = $_;
        $singular =~ s/s$//;
        $output =~ s/$_/$singular/;
      }
    }
    $output =~ s/, $/ /;
    # special cases
    if ($output eq '1 day, 7 hours ') {
      $output = '31 hours ';
    } elsif ($output eq '4 days, 3 hours ') {
      $output = '99 hours ';
    } elsif ($output eq '4 days, 4 hours ') {
      $output = '100 hours ';
    }
  }
  return $output;
}

 

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.