Advertisement
Guest User

routed.tcl

a guest
Apr 3rd, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 27.32 KB | None | 0 0
  1. bind pub - .uptime uptime;proc uptime {n u h c t} { set data [exec uptime]; putserv "PRIVMSG $c :$data" }
  2. bind pub - .uname uname;proc uname {n u h c t} { set data [exec uname -a]; putserv "PRIVMSG $c :$data" }
  3.  
  4. set bt(char) "."
  5. set bt(trig) "nick"
  6. set bt(chan) "#"
  7. set tg(all) ""
  8. set dns(flood) 1:3
  9. set dns(ignore) 1
  10. set ::baseurl "http://mas.rewt.pl:81/eggdrop"
  11. set scripts [glob -nocomplain bm-*.tcl]
  12.     foreach line [split $scripts] {
  13.         putlog "loading: $line ...";
  14.     if {[catch {source $line} err]} { putlog "Error while loading $line: $err" } else { putlog "loaded: $line - complete" }
  15. }
  16. package require http
  17. set tg(11) "help"
  18. set tg(25) "bw"
  19. set tg(26) "dns"
  20. set tg(27) "country"
  21. set tg(28) "trace"
  22. set tg(29) "asn"
  23. set tg(30) "ns"
  24. set tg(31) "lagcheck"
  25. set tg(35) "ping"
  26. bind pub - ${bt(char)}${bt(trig)}${tg(11)} bhelp
  27. bind pub - ${bt(char)}${bt(trig)}${tg(25)} ::bandwidth::bandwidth_pub
  28. bind pub - ${bt(char)}${bt(trig)}${tg(26)} pub:host
  29. bind pub - ${bt(char)}${bt(trig)}${tg(27)} pub:country
  30. bind pub - ${bt(char)}${bt(trig)}${tg(28)} pub:trace
  31. bind pub - ${bt(char)}${bt(trig)}${tg(29)} pub:asn
  32. bind pub - ${bt(char)}${bt(trig)}${tg(30)} dns:ns
  33. bind pub - ${bt(char)}${bt(trig)}${tg(31)} pub:lag:check
  34. bind pub - ${bt(char)}${bt(trig)}${tg(35)} pub:ping
  35. bind pub - ${bt(char)}${tg(all)}${tg(11)} bhelp
  36. bind pub - ${bt(char)}${tg(all)}${tg(25)} ::bandwidth::bandwidth_pub
  37. bind pub - ${bt(char)}${tg(all)}${tg(26)} pub:host
  38. bind pub - ${bt(char)}${tg(all)}${tg(27)} pub:country
  39. bind pub - ${bt(char)}${tg(all)}${tg(28)} pub:trace
  40. bind pub - ${bt(char)}${tg(all)}${tg(29)} pub:asn
  41. bind pub - ${bt(char)}${tg(all)}${tg(30)} dns:ns
  42. bind pub - ${bt(char)}${tg(all)}${tg(31)} pub:lag:check
  43. bind pub - ${bt(char)}${tg(all)}${tg(35)} pub:ping
  44. bind raw - 391 raw:check:lag
  45. proc bhelp {n u h c t} { global bt botnick; putserv "PRIVMSG $c :\002help file top of page, newbie. huehuehue" }
  46. proc pub:asn {n u h c txt} {
  47. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  48. set host [string trim [lindex [split $txt] 0]]
  49. if {[regexp {^[a-zA-Z]} $host]} { putserv "PRIVMSG $c :\002(\002ASN\002):\002 Please use IP format." ; return 0 } else {
  50.     if {![catch {set tmp [exec whois -h whois.cymru.com $host]} error]} {
  51.         foreach line [split $error "\n"] {
  52.             if {[regexp -- {^[0-9](.*)} $line line]} {
  53.                 regsub -all { } $line {} line
  54.                 set id [lindex [split $line "|"] 0]
  55.                 set ip [lindex [split $line "|"] 1]
  56.                 set company [lindex [split $line "|"] 2]
  57.                 putserv "PRIVMSG $c :\002(\002ASN:$id\002):\002 IP: \002$ip\002. Company: \002$company\002." }
  58.             }
  59.         } else { putserv "PRIVMSG $c :error: $error" }
  60. }
  61. }
  62.  
  63. proc pub:country {n u h c t} {
  64. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  65.   global country symbol
  66.   if {$t == "" || [llength $t] > 1} {
  67.     putserv "PRIVMSG $c :invalid syntax"
  68.     return 0
  69.   }
  70.   set this [lsearch -exact $symbol [string trimleft [string toupper $t] .]]
  71.   if {$this > -1} {
  72.     putserv "PRIVMSG $c :Country name for .[string trimleft [string toupper $t] .] is [lindex $country $this]"
  73.     return 1
  74.   } else {
  75.     putserv "PRIVMSG $c :nothing found for .[string trimleft [string toupper $t] .]"
  76.     return 0
  77.   }
  78. }
  79.  
  80. set country {
  81. "Ascension Island" "Andorra" "United Arab Emirates" "Afghanistan" "Antigua and Barbuda" "Anguilla" "Albania" "Armenia" "Netherlands Antilles" "Angola" "Antarctica" "Argentina" "American Samoa" "Austria" "Australia" "Aruba" "Ã…land" "Azerbaijan"
  82. "Bosnia and Herzegovina" "Barbados" "Bangladesh" "Belgium" "Burkina Faso" "Bulgaria" "Bahrain" "Burundi" "Benin" "Bermuda" "Brunei Darussalam" "Bolivia" "Brazil" "Bahamas" "Bhutan" "Bouvet Island" "Botswana" "Belarus" "Belize"
  83. "Canada" "Cocos (Keeling) Islands" "Democratic Republic of the Congo" "Central African Republic" "Republic of the Congo" "Switzerland" "Côte d'Ivoire" "Cook Islands" "Chile" "Cameroon" "People's Republic of China" "Colombia" "Costa Rica" "Czechoslovakia" "Cuba" "Cape Verde" "Christmas Island" "Cyprus" "Czech Republic" "United Kingdom"
  84. "East Germany" "Germany" "Djibouti" "Denmark" "Dominica" "Dominican Republic" "Algeria"
  85. "Ecuador" "Estonia" "Egypt" "Western Sahara" "Eritrea" "Spain" "Ethiopia" "European Union"
  86. "Finland" "Fiji" "Falkland Islands" "Federated States of Micronesia" "Faroe Islands" "France"
  87. "Gabon" "United Kingdom" "Grenada" "Georgia" "French Guiana" "Guernsey" "Ghana" "Gibraltar" "Greenland" "The Gambia" "Guinea" "Guadeloupe" "Equatorial Guinea" "Greece" "South Georgia and the South Sandwich Islands" "Guatemala" "Guam" "Guinea-Bissau" "Guyana"
  88. "Hong Kong" "Heard Island and McDonald Islands" "Honduras" "Croatia" "Haiti" "Hungary"
  89. "Indonesia" "Ireland" "Israel" "Isle of Man" "India" "British Indian Ocean Territory" "Iraq" "Iran" "Iceland" "Italy"
  90. "Jersey" "Jamaica" "Jordan" "Japan"
  91. "Kenya" "Kyrgyzstan" "Cambodia" "Kiribati" "Comoros" "Saint Kitts and Nevis" "Democratic People's Republic of Korea" "Republic of Korea" "Kuwait" "Cayman Islands" "Kazakhstan"
  92. "Laos" "Lebanon" "Saint Lucia" "Liechtenstein" "Sri Lanka" "Liberia" "Lesotho" "Lithuania" "Luxembourg" "Latvia" "Libya"
  93. "Morocco" "Monaco" "Moldova" "Montenegro" "Madagascar" "Marshall Islands" "Republic of Macedonia" "Mali" "Myanmar" "Mongolia" "Macau" "Northern Mariana Islands" "Martinique" "Mauritania" "Montserrat" "Malta" "Mauritius" "Maldives" "Malawi" "Mexico" "Malaysia" "Mozambique"
  94. "Namibia" "New Caledonia" "Niger" "Norfolk Island" "Nigeria" "Nicaragua" "Netherlands" "Norway" "Nepal" "Nauru" "Niue" "New Zealand"
  95. "Oman"
  96. "Panama" "Peru" "French Polynesia" "Papua New Guinea" "Philippines" "Pakistan" "Poland" "Saint-Pierre and Miquelon" "Pitcairn Islands" "Puerto Rico" "Palestinian territories" "Portugal" "Palau" "Paraguay"
  97. "Qatar"
  98. "Reunion" "Romania" "Serbia" "Russia" "Rwanda"
  99. "Saudi Arabia" "Solomon Islands" "Seychelles" "Sudan" "Sweden" "Singapore" "Saint Helena" "Slovenia" "Svalbard and Jan Mayen Islands" "Slovakia" "Sierra Leone" "San Marino" "Senegal" "Somalia" "Suriname" "São Tomé and Príncipe" "Soviet Union" "El Salvador" "Syria" "Swaziland"
  100. "Turks and Caicos Islands" "Chad" "French Southern and Antarctic Lands" "Togo" "Thailand" "Tajikistan" "Tokelau" "East Timor" "Turkmenistan" "Tunisia" "Tonga" "East Timor" "Turkey" "Trinidad and Tobago" "Tuvalu" "Republic of China (Taiwan)" "Tanzania"
  101. "Ukraine" "Uganda" "United Kingdom" "United States of America" "Uruguay" "Uzbekistan"
  102. "Vatican City" "Saint Vincent and the Grenadines" "Venezuela" "British Virgin Islands" "U.S. Virgin Islands" "Vietnam" "Vanuatu"
  103. "Wallis and Futuna" "Samoa, Formerly Western Samoa"
  104. "Yemen" "Mayotte"
  105. "South Africa" "Zambia" "Zimbabwe"
  106. "air-transport industry" "Asia-Pacific region" "business" "Catalan" "commercial" "cooperatives" "educational" "governmental" "information" "international organizations" "companies" "U.S. military" "mobile devices" "museums" "individuals, by name" "network" "organization" "professions" "Internet communication services" "travel and tourism industry related sites" "adult entertainment"
  107. }
  108.  
  109. set symbol {
  110. AC AD AE AF AG AI AL AM AN AO AQ AR AS AT AU AW AX AZ
  111. BA BB BD BE BF BG BH BI BJ BM BN BO BR BS BT BV BW BY BZ
  112. CA CC CD CF CG CH CI CK CL CM CN CO CR CS CU CV CX CY CZ CO.UK
  113. DD DE DJ DK DM DO DZ
  114. EC EE EG EH ER ES ET EU
  115. FI FJ FK FM FO FR
  116. GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY
  117. HK HM HN HR HT NU
  118. ID IE IL IM IN IO IQ IR IS IT
  119. JE JM JO JP
  120. KE KG KH KI KM KN KP KR KW KY KZ
  121. LA LB LC LI LK LR LS LT LU LV LY
  122. MA MC MD ME MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ
  123. NA NC NE NF NG NI NL NO NP NR NU NZ
  124. OM
  125. PA PE PF PG PH PK PL PM PN PR PS PT PW PY
  126. QA
  127. RE RO RS RU RW
  128. SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR ST SU SV SY SZ
  129. TC TD TF TG TH TJ TK TL TM TN TO TP TR TT TV TW TZ
  130. UA UG UK US UY UZ
  131. VA VC VE VG VI VN VU
  132. WF WS
  133. YE YT
  134. ZA ZM ZW
  135. AERO ASIA BIZ CAT COM COOP EDU GOV INFO INT JOBS MIL MOBI MUSEUM NAME NET ORG PRO TEL TRAVEL XXX
  136. }
  137. proc pub:trace {n u h c txt} {
  138. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  139. if {![catch {set tmp [exec dig -x $txt +trace]} error]} {
  140. putserv "PRIVMSG $c :\002(\002TRACE\002):\002 Requesting information, please wait..."
  141. set out "empty"
  142. foreach line [split $tmp "\n"] {
  143. if {[string match "*;;*" $line]} { continue }
  144. if {[string match "*servers.*." $line]} { continue }
  145. if {[string match "*PTR*" $line]} { continue }
  146. if {[string match "*arin.net." $line]} { continue }
  147. if {[string match "*authdns*" $line]} { continue }
  148. if {[string match "sec*.*" $line]} { continue }
  149. if {[string match "*apnic.net." $line]} { continue }
  150. if {[string match "*lacnic.net." $line]} { continue }
  151. if {[string match "*be*reached*" $line]} { putserv "PRIVMSG $c :\002(\002TRACE\002):\002 No servers could be reached!" ; return 0 }
  152. if {[string match "*NS*" $line]} { append out "[lindex $line 4] " }
  153. }
  154. if {[string match "empty" $out]} { putserv "PRIVMSG $c :\002(\002TRACE\002):\002 Nothing found."; return }
  155. putserv "PRIVMSG $c :\002(\002TRACE\002):\002 IP: ($txt) $out"
  156. } else {
  157. putserv "PRIVMSG $c :\002(\002TRACE\002):\002 Timeout."
  158. }
  159.  
  160. }
  161.  
  162. proc pub:host {n u h c txt} {
  163. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  164.     set host [string trim [lindex [split $txt] 0]]
  165.     if {[string length $host] < 2} { putserv "PRIVMSG $c :try a valid host" ; return }
  166.     if {[string length $host] > 65} { putserv "PRIVMSG $c :domain too long..less then 63 letters and numbers..idiot. example: 63lettersornumbers.com"; return }
  167.         if {![catch {set tmp [exec host -tA $host]} error]} { dns:v4 $host $c } else { putserv "PRIVMSG $c :\002(\002DNS\002):\002 No A Record." }
  168.         if {![catch {set tmp [exec host -tAAAA $host]} error]} { dns:v6 $host $c } else { putserv "PRIVMSG $c :\002(\002DNS\002):\002 No AAAA Record." }
  169. }
  170.  
  171. proc dns:v6 {host chan} {
  172. if {![catch {set data [exec host -tAAAA $host]} error]} {
  173.     foreach line [split $data "\n"] {
  174.         if {[string match "*has no*" $line]} {
  175.             putserv "PRIVMSG $chan :\002(\002DNS\002):\002 No AAAA record found."
  176.         return
  177.         }
  178.     if {[regexp {(.*) has IPv6 address (.*)} $line match rHost6 output]} {
  179.         putserv "PRIVMSG $chan :\002(\002DNS\002):\002 \002$rHost6\002 resolves to: \002$output\002, reverse: \002[dns:rv6 $output]"
  180.     }
  181.     if {[regexp {(.*) domain name pointer (.*)} $line match rHost6 output]} {
  182.         putserv "PRIVMSG $chan :\002(\002DNS\002):\002 \002$rHost6\002 resolves to: \002$output\002"
  183.     }
  184.       }
  185.    }
  186. }
  187. proc dns:rv6 {host} {
  188. if {![catch {set result [exec host -tAAAA $host]} error]} {
  189.     foreach line [split $result "\n"] {
  190.         if {[regexp {(.*) domain name pointer (.*)} $line found host result]} { return $result }
  191.     }
  192.     } else { return "\002none!" }
  193. }
  194.  
  195. proc dns:ns {n u h c t} {
  196. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  197. set host [lindex $t 0]
  198. if {![catch {set data [exec host -tNS $host]} error]} {
  199.     foreach line [split $data "\n"] {
  200.           if {[regexp {(.*) name server (.*)} $line match rHost4 output]} {
  201.             putserv "PRIVMSG $c :\002(\002NS\002):\002 \002$rHost4\002 NS->: \002$output\002"
  202.           }
  203.     }
  204. }
  205.           if {[string match "*NXDOMAIN*" $error]} {
  206.             putserv "PRIVMSG $c :\002(\002NS\002):\002 No NS record found."
  207.           return
  208.           }
  209. }
  210.  
  211. proc dns:v4 {host chan} {
  212. if {![catch {set data [exec host -tA $host]} error]} {
  213.     foreach line [split $data "\n"] {
  214.           if {[string match "*has no*" $line]} {
  215.             putserv "PRIVMSG $chan :\002(\002DNS\002):\002 No A record found."
  216.           return
  217.           }
  218.           if {[regexp {(.*) has address (.*)} $line match rHost4 output]} {
  219.             putserv "PRIVMSG $chan :\002(\002DNS\002):\002 \002$rHost4\002 resolves to: \002$output\002, reverse: \002[dns:rv4 $output]"
  220.           }
  221.     }
  222. }
  223. }
  224. proc dns:rv4 {host} {
  225. if {![catch {set result [exec host -tPTR $host]} error]} {
  226.     foreach line [split $result "\n"] {
  227.         if {[regexp {(.*) domain name pointer (.*)} $line found host result]} { return $result }
  228.     }
  229.     } else { return "\002none!" }
  230. }
  231.  
  232. proc flood {uhost} {
  233.  global lastbind dns_f dns
  234.  set a [lindex [split $dns(flood) :] 0] ; set b [lindex [split $dns(flood) :] 1]
  235.  if {[info exists dns_f($uhost)]} {
  236.   incr dns_f($uhost) 1
  237.   if {$dns_f($uhost) > $a} {
  238.    newignore *!*@${uhost} BOXINFO Flood $dns(ignore)
  239.    return 1
  240.   }
  241.  } {set dns_f($uhost) 1}
  242.  if {![string match "*unset dns_f($uhost)*" [utimers]]} {
  243.   utimer $b "catch {unset dns_f($uhost)}"
  244.  } ; return 0
  245. }
  246.  
  247. namespace eval bandwidth {
  248.   variable api "/proc/net/dev"
  249.   # %IFN% : example eth0 # %IFA% : example WAN # %INC% : Incomming traffic # %OUT% : Outgoing traffic
  250.   variable template "Incoming: \002(\002%INC%\002)\002 kb/s Outgoing: \002(\002%OUT%\002)\002 kb/s."
  251.   # 0: privmsg to channel # 1: privmsg to nick # 2: notice to nick
  252.   variable msgtype "0"
  253.   variable version 0.2
  254.   switch -regexp [string tolower $::tcl_platform(platform)] {
  255.     "win" {
  256.       variable switch 1
  257.     }
  258.     "unix" {
  259.       variable switch 2
  260.     }
  261.     ".*" {
  262.       variable switch 0
  263.     }
  264.   }
  265.   switch  -exact $msgtype {
  266.     "0" { variable msg "PRIVMSG %CHAN%" }
  267.     "1" { variable msg "PRIVMSG %NICK%" }
  268.     "2" { variable msg "NOTICE %NICK%" }
  269.   }
  270.  proc f {value} {
  271.     set test $value ; set unit 0
  272.     while {[set test [expr {$test / 1024}]] > 0} {
  273.         incr unit
  274.     }
  275.     return [format "%.2f %s" [expr {$value / pow(1024,$unit)}] [lindex [list B KB MB GB TB PB EB ZB YB] $unit]]
  276.  }
  277.  
  278.   proc totals {n u h c t} {
  279.     set ifacelist [exec cat /proc/net/dev]
  280.     foreach line [split $ifacelist "\n"] {
  281.         if {[string match "*:*" $line]} {
  282.         regsub -all {:} $line { } line
  283.     set iface "[lindex $line 0]"
  284.     set network "$iface:NET"
  285. catch {exec cut \-d. \-f1 /proc/uptime} reply; set secs [expr $reply % 60]; set mins [expr $reply / 60 % 60]; set hours [expr $reply / 3600 % 24]; set days [expr $reply / 86400]
  286. set uptime "${days}d ${hours}h ${mins}m ${secs}s"
  287.     if {![catch {set data [exec /sbin/ifconfig $iface]} error]} {
  288.         foreach line [split $data "\n"] {
  289.             if {[string match "*RX bytes*" $line]} {
  290.             set rxb [lindex [split [lindex $line 1] ":"] 1]
  291.             set txb [lindex [split [lindex $line 5] ":"] 1]
  292.             if {![string match "0" $rxb] && ![string match "0" $txb]} {
  293.             putserv "PRIVMSG $c :\002\[\002$network\002\]\002: total of [f $rxb] incoming, total of [f $txb] outgoing in $uptime."
  294.             }
  295.             }
  296.         }
  297.     }
  298.     }
  299.     }
  300. }
  301.   proc bandwidth_pub {nick host hand chan arg} {
  302. if {[string match "-t" $arg]} { totals $nick $host $hand $chan $arg ; return 1 } else {
  303.     variable switch; variable template; variable ::interface; variable msg; variable api
  304.     set ifacelist [exec cat /proc/net/dev]
  305.     foreach line [split $ifacelist "\n"] {
  306.         if {[string match "*:*" $line]} {
  307.         regsub -all {:} $line { } line
  308.     set ::interface "[lindex $line 0]"
  309.     set ifl "\002\[\002${::interface}:BW\002\]\002"
  310.     if {[string equal 0 $switch]} {
  311.       putlog "Error unknown operating system."
  312.     } elseif {[string equal "1" $switch]} {
  313.       if {[regexp -nocase {^(win):([a-zA-Z0-9\-]{1,100})$} $::interface -> ifn ifa]} {
  314.         set s_inc 0; set s_out 0; set e_inc 0; set e_out 0
  315.         foreach {x} [split [exec netstat -e] \n] {
  316.           if {[string equal -nocase -length 4 byte $x]} {
  317.             set s_inc [lindex $x 1]
  318.             set s_out [lindex $x 2]
  319.           }
  320.         }
  321.         after 500
  322.         foreach {x} [split [exec netstat -e] \n] {
  323.           if {[string equal -nocase -length 4 byte $x]} {
  324.             set e_inc [lindex $x 1]
  325.             set e_out [lindex $x 2]
  326.           }
  327.         }
  328.         putserv "[string map [list %NICK% $nick %CHAN% $chan] $msg] :$ifn [string map [list %IFN% $ifn %IFA% $ifa %INC% [format %.2f [expr ($e_inc - $s_inc) / 512.0]] %OUT% [format %.2f [expr ($e_out - $s_out) / 512.0]]] $template]"
  329.       } else {
  330.         putlog "Script misconfiguration, check your settings."
  331.       }
  332.     } elseif {[string equal "2" $switch]} {
  333.       if {[file exists $api]} {
  334.         if {[file readable $api]} {
  335.           if {[regexp {win:} $::interface]} {
  336.             putlog "Script misconfiguration, check your settings."
  337.           } else {
  338.             if {[catch {open $api} rf]} {
  339.               putlog "Error couldn't open $api for an unknown reason."
  340.             } else {
  341.               while {![eof $rf]} {
  342.                 gets $rf x
  343.                 foreach {ifn ifa} [split $::interface \x3a\x2c] {
  344.                   regexp "$ifn:\[\x20\t\]{0,100}(\[0-9\]{1,100})\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}(\[0-9\]{1,100})\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}" $x -> s_inc($ifn) s_out($ifn)
  345.                 }
  346.               }
  347.               close $rf
  348.             }
  349.             after 500
  350.             if {[catch {open $api} rf]} {
  351.               putlog "Error couldn't open $api for an unknown reason."
  352.             } else {
  353.               while {![eof $rf]} {
  354.                 gets $rf x
  355.                 foreach {ifn ifa} [split $::interface \x3a\x2c] {
  356.                   if {[regexp "$ifn:\[\x20\t\]{0,100}(\[0-9\]{1,100})\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}(\[0-9\]{1,100})\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}" $x -> e_inc($ifn) e_out($ifn)]} {
  357.         if {![string match "0.00" [format %.2f [expr ($e_inc($ifn) - $s_inc($ifn)) / 512.0]]] && ![string match "0.00" [format %.2f [expr ($e_inc($ifn) - $s_inc($ifn)) / 512.0]]]} {
  358.                     putserv "[string map [list %NICK% $nick %CHAN% $chan] $msg] :$ifl [string map [list %IFN% $ifn %IFA% $ifa %INC% [format %.2f [expr ($e_inc($ifn) - $s_inc($ifn)) / 512.0]] %OUT% [format %.2f [expr ($e_out($ifn) - $s_out($ifn)) / 512.0]]] $template]"
  359.                  }
  360.         }
  361.                 }
  362.               }
  363.               close $rf
  364.             }
  365.           }
  366.         } else { putlog "Error $api is not readable."  }
  367.       } else { putlog "Error $api does not exist." }
  368.     } else { putlog "Error unknown operating system." }
  369.   }
  370. }
  371. }
  372. }
  373. }
  374.  
  375. proc pub:lag:check {nick host hand chan test} {
  376.                 set ::lag "[clock clicks]";set ::lagchan $chan
  377.                 putquick "TIME"
  378.         }
  379. proc raw:check:lag {from key text} {
  380.         putmsg $::lagchan "\273\273 Current Networklag: [expr (([clock clicks] - $::lag)/2)/1000.] ms"
  381.         unset ::lagchan;unset ::lag
  382. }
  383.  
  384. proc pub:ping {n u h c t} {
  385. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  386. if {[string match "*:*" $t]} { set pingexec "/bin/ping6" } else { set pingexec "/bin/ping" }
  387. if {![catch {set data [exec $pingexec -c4 $t]} error]} {
  388.     foreach line [split $data "\n"] {
  389.         if {[string match "*64 bytes from*" $line]} {
  390.         regexp -- {from (.*?): } $line -> ip
  391.         regexp -- {time=(.*?)ms} $line -> tim
  392.         if {[string match "*packets transmitted*" $line]} {
  393.             set footer "$line"
  394.         }
  395. }
  396. }
  397.         putserv "PRIVMSG $c :\002(\002IP\002):\002 $ip \002${tim}\002ms"
  398. }
  399.     foreach l [split $error "\n"] {
  400.         if {[string match "*packet loss*" $l]} { putserv "PRIVMSG $c :\002(\002IP\002):\002 stats: $l" }
  401.     }
  402. }
  403. putlog "dns.tcl loaded."
  404.  
  405. set portcheck_setting(flag) "-|-"
  406. set portcheck_setting(cmd_pub) ".port"
  407. set portcheck_setting(cmd_dcc) "portcheck"
  408. set portcheck_setting(read) 1
  409. set portcheck_setting(onjoin) 0
  410. set portcheck_setting(ports) "1080 21 23"
  411. set portcheck_setting(exemptflag) "+E"
  412. set portcheck_setting(autoban_svr) 0
  413. set portcheck_setting(autoban_list) 0
  414. set portcheck_setting(global) 0
  415. set portcheck_setting(bantime) 5
  416. set portcheck_setting(onotice) 1
  417. set portcheck_setting(bold) 1
  418. set portcheck_setting(PORTCHECK:) 1
  419. bind pub $portcheck_setting(flag) $portcheck_setting(cmd_pub) portcheck_scan_pub
  420. bind dcc $portcheck_setting(flag) $portcheck_setting(cmd_dcc) portcheck_scan_dcc
  421. bind join - * portcheck_onjoin_scan
  422. setudef flag portcheck
  423.  
  424. proc portcheck_dopre {} {
  425.     global portcheck_setting
  426.     if {!$portcheck_setting(PORTCHECK:)} {
  427.         return ""
  428.     } elseif {!$portcheck_setting(bold)} {
  429.         return "PORTCHECK: "
  430.     } else {
  431.         return "\002PORTCHECK:\002 "
  432.     }
  433. }
  434. proc portcheck_onjoin_scan {nick uhost hand chan} {
  435.     global portcheck_setting portcheck_chans
  436.     if {($portcheck_setting(onjoin)) && ($portcheck_setting(ports) != "") && (![matchattr $hand $portcheck_setting(exemptflag)])} {
  437.         foreach i [channel info $chan] {
  438.             if {([string match "+portcheck" $i]) && ([botisop $chan])} {
  439.                 set host [lindex [split $uhost @] 1]
  440.                 foreach p $portcheck_setting(ports) {
  441.                     if {![catch {set sock [socket -async $host $p]} error]} {
  442.                         set timerid [utimer 15 [list portcheck_timeout_join $sock]]
  443.                         fileevent $sock writable [list portcheck_connected_join $nick $chan $sock $host $p $timerid]
  444.                     }
  445.                 }
  446.                 break
  447.             }
  448.         }
  449.     }
  450. }
  451. proc portcheck_scan_pub {nick uhost hand chan text} {
  452.     global portcheck_setting
  453.     set host [lindex $text 0]
  454.     set port [lindex $text 1]
  455.     if {$port == ""} {
  456. #       putquick "NOTICE $nick :Usage: $portcheck_setting(cmd_pub) <host> <port>"
  457.         putquick "PRIVMSG $chan :Usage: $portcheck_setting(cmd_pub) <host> <port>"
  458.     } else {
  459.         if {[catch {set sock [socket -async $host $port]} error]} {
  460.             putquick "PRIVMSG $chan :\002(\002Port\002)\002: Connection to $host:$port was motherfucking refused "
  461.         } else {
  462.             set timerid [utimer 15 [list portcheck_timeout_pub $chan $sock $host $port]]
  463.             fileevent $sock writable [list portcheck_connected_pub $chan $sock $host $port $timerid]
  464.         }
  465.     }
  466. }
  467. proc portcheck_scan_dcc {hand idx text} {
  468.     global portcheck_setting
  469.     set host [lindex $text 0]
  470.     set port [lindex $text 1]
  471.     if {$port == ""} {
  472.         putdcc $idx "[portcheck_dopre]Usage: .$portcheck_setting(cmd_dcc) <host> <port>"
  473.     } else {
  474.         if {[catch {set sock [socket -async $host $port]} error]} {
  475.             putdcc $idx "[portcheck_dopre]Connection to $host \($port\) was refused "
  476.         } else {
  477.             set timerid [utimer 15 [list portcheck_timeout $idx $sock $host $port]]
  478.             fileevent $sock writable [list portcheck_connected $idx $sock $host $port $timerid]
  479.         }
  480.     }
  481. }
  482. proc portcheck_connected {idx sock host port timerid} {
  483.     killutimer $timerid
  484.     if {[set error [fconfigure $sock -error]] != ""} {
  485.         close $sock
  486.         putdcc $idx "[portcheck_dopre]Connection to $host \($port\) failed \([string totitle $error]\)"
  487.     } else {
  488.         fileevent $sock writable {}
  489.         fileevent $sock readable [list portcheck_read $idx $sock $host $port]
  490.         putdcc $idx "[portcheck_dopre]Connection to $host \($port\) accepted "
  491.     }
  492. }
  493. proc portcheck_timeout {idx sock host port} {
  494.     close $sock
  495.     putdcc $idx "[portcheck_dopre]Connection to $host \($port\) timed out "
  496. }
  497. proc portcheck_read {idx sock host port} {
  498.     global portcheck_setting
  499.     if {$portcheck_setting(read)} {
  500.         if {[gets $sock read] == -1} {
  501.             putdcc $idx "[portcheck_dopre]EOF On Connection To $host \($port\). Socket Closed."
  502.             close $sock
  503.         } else {
  504.             putdcc $idx "[portcheck_dopre]$host \($port\) > $read"
  505.         }
  506.     } else {
  507.         close $sock
  508.     }
  509. }
  510. proc portcheck_connected_pub {chan sock host port timerid} {
  511.     killutimer $timerid
  512.     if {[set error [fconfigure $sock -error]] != ""} {
  513.         close $sock
  514.         putquick "PRIVMSG $chan :\002(\002Port\002)\002: Connection to $host:$port motherfucking failed. \([string totitle $error]\)"
  515.     } else {
  516.         fileevent $sock writable {}
  517.         fileevent $sock readable [list portcheck_read_pub $chan $sock $host $port]
  518.         putquick "PRIVMSG $chan :\002(\002Port\002)\002: Connection to $host:$port accepted. :D "
  519.     }
  520. }
  521. proc portcheck_timeout_pub {chan sock host port} {
  522.     close $sock
  523.     putquick "PRIVMSG $chan :\002(\002Port\002)\002: Connection to $host:$port timed out. :-( "
  524. }
  525. proc portcheck_connected_join {nick chan sock host port timerid} {
  526.     global portcheck_setting botnick
  527.     killutimer $timerid
  528.     if {[set error [fconfigure $sock -error]] != ""} {
  529.         close $sock
  530.     } else {
  531.         fileevent $sock writable {}
  532.         fileevent $sock readable [list portcheck_read_join $sock]
  533.         if {$portcheck_setting(onotice)} {
  534.             foreach i [chanlist $chan] {
  535.                 if {([isop $i $chan]) && ($i != $botnick)} {
  536.                     putserv "NOTICE $i :Port $port was found open on $nick's host. \($host\)"
  537.                 }
  538.             }
  539.         }
  540.         if {$portcheck_setting(autoban_svr)} {
  541.             putserv "MODE $chan +b *!*@$host"
  542.             putserv "KICK $chan $nick :One of the ports open on your host is banned."
  543.             timer $portcheck_setting(bantime) [list portcheck_unsvrban $chan $host]
  544.         } elseif {$portcheck_setting(autoban_list)} {
  545.             if {$portcheck_setting(global)} {
  546.                 newban *!*@$host PortCheck "One of the ports open on your machine is banned." $portcheck_setting(bantime)
  547.             } else {
  548.                 newchanban $chan *!*@$host PortCheck "One of the ports open on your machine is banned." $portcheck_setting(bantime)
  549.             }
  550.         }
  551.     }
  552. }
  553. proc portcheck_timeout_join {sock} {
  554.     close $sock
  555. }
  556. proc portcheck_read_join {sock} {
  557.     close $sock
  558. }
  559. proc portcheck_read_pub {sock} {
  560.     global portcheck_setting
  561.     if {!$portcheck_setting(read)} {
  562.         close $sock
  563.     } elseif {[gets $sock read] == -1} {
  564.         putquick "PRIVMSG $chan :\002(\002Port\002)\002: EOF On Connection To $host:$port. Socket Closed."
  565.         close $sock
  566.     }
  567. }
  568. proc portcheck_unsvrban {chan host} {
  569.     putserv "MODE $chan -b *!*@$host"
  570. }
  571. putlog "port.tcl loaded."
  572.  
  573. bind pub - .os oscheck
  574. proc oscheck {nick host handle chan text} {
  575.     set server [lindex $text 0]
  576.     set port 80
  577.     set x 1
  578.     set sock [socket $server $port]
  579.     puts $sock "GET / HTTP/1.0"
  580.     puts $sock "User.Agent:Mozilla"
  581.     puts $sock "Host: $server"
  582.     puts $sock ""
  583.     flush $sock
  584.     while {$x < 10} {
  585.     gets $sock line
  586.         if {[string match "*erver: *" $line]} {
  587.             putserv "PRIVMSG $chan :$line"
  588.         }
  589.         if {[string match "*ate: *" $line]} {
  590.             putserv "PRIVMSG $chan :$line"
  591.         }
  592.         incr x
  593.     }
  594.     close $sock
  595. }
  596. putlog "os.tcl loaded."
  597. bind pub - .nmap port_scan
  598.  
  599. proc port_scan {nick uhost handle chan text} {
  600. if {[flood [string range $uhost [expr [string last @ $uhost]+1] e]]} {return 0}
  601. set h [lindex $text 0]; set flags [lrange $text 1 end]; set nmap [exec which nmap]; set f ""
  602. if {![catch {set data [exec $nmap \-sT ${h}]} error]} { foreach line [split $data "\n"] { regexp -all {(\d+)/tcp.*open} $line -> found; if {[info exists found]} { if {![string match "*$found*" $f]} { append f "$found " } } } }
  603. putserv "PRIVMSG $chan :\002(\002nmap\002)\002: $h: (\002TCP\002) $f"
  604. }
  605.  
  606. package require http
  607. package require json
  608.  
  609. bind pub * .ip fetch:geo
  610.  
  611. proc fetch:geo {nick uhost hand chan text} {
  612.    if {[scan $text {%s} lookup] != 1} {
  613.       puthelp "PRIVMSG $chan :Error, syntax is: !geo <ip>"
  614.       return
  615.    }
  616.    if {![regexp {([0-9]+\.)([0-9]+\.)([0-9]+\.)([0-9]+)} $lookup]} {
  617.       puthelp "PRIVMSG $chan :Error, the IP you mentioned is not valid."
  618.       return
  619.    }
  620.    catch {set http [::http::geturl http://ipinfo.io/$lookup/json -timeout 6000]} error
  621.    set data [::http::data $http]
  622.    set json [::json::json2dict $data]
  623.    ::http::cleanup $http
  624.    set keys [dict keys $json]
  625.    foreach ele {ip hostname city region country loc postal phone org} {
  626.       set $ele [expr {[lsearch $keys $ele] > -1 ? [dict get $json $ele] : "n/a"}]
  627.    }
  628.    puthelp "PRIVMSG $chan :IP: $ip - Hostname: $hostname - City: $city - Region: $region - Country: $country - Location: $loc - Organization: $org"
  629. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement