All pastes #833608 Raw Edit

Unnamed

public text v1 · immutable
#833608 ·published 2007-12-27 12:58 UTC
rendered paste body
on *:JOIN:#scrim:{
  if ($regex($address($nick,2),/((\d+).(\d+).(\d+).(\d+))$/)) {
    checkip $nick $regml(1) 
  }
}

alias checkip {
  sockclose apnic
  sockopen apnic www.apnic.net 80
  %whois.nick = $1
  %whois.ip = $2-
  set %ip.ticks. [ $+ [ $1 ] ] $ticks
}

on *:SOCKOPEN:apnic:{
  if ($sockerr) echo -a $v1
  var %a = sockwrite -n $sockname
  var %string = $urlencode_string(searchtext= $+ %whois.ip)
  %a GET /apnic-bin/whois.pl? $+ %string HTTP/1.0
  %a Host: www.apnic.net
  %a Connection: close
  ; %a Content-Length: $len(%string)
  ; %a Content-Type: application/x-www-form-urlencoded
  %a Accept: */*
  %a Accept-Charset: *
  %a Accept-Encoding: *
  %a Accept-Language: *
  %a User-Agent: Mozilla/5.0
  %a $crlf 
}

alias cap {
  return $+($upper($left($1-,1)),$lower($right($1-,$calc($len($1-) - 1))))
}

on *:SOCKREAD:apnic:{
  var %temp
  sockread -f %temp
  ;aline @ipinfo %temp
  if ($regex(%temp,/country:(\s*)(\w+)/i)) {
    if ($readini(country.ini,abb,$regml(2))) {
      %whois.country = $cap($readini(country.ini,abb,$regml(2)))
    }
    if ($regml(2) != NZ) && ($regml(2) != AU) {
      .msg chanserv addtimedban #scrim %whois.nick 1w Bad IP: %whois.ip $+ , from %whois.country ( $+ $regml(2) $+ ). 
    }
   sockclose $sockname
  }
}

alias urlencode_string {
  ; Encodes a whole string of data in the format name1=data1&name2=data2
  ; Example: $urlencode_string(name1=test&name2=test2)
  ; Returns: name1=%74%65%73%74&name2=%74%65%73%74%32
  var %a = 1, %string = $1, %output
  while ($gettok(%string,%a,38)) {
    tokenize 61 $v1
    if (%a != 1) %output = %output $+ &
    %output = $+(%output,$1,=,$urlencode($2))
    inc %a
  }
  return %output
}

alias urlencode {
  var %a = $regsubex($$1,/([^\w\s])/Sg,$+(%,$base($asc(\t),10,16,2)))
  return $replace(%a,$chr(32),$chr(43))
}