Advertisement
s4turns

dns.tcl

Jul 31st, 2019
3,146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 21.49 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) ""
  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(26) "dns"
  18. set tg(27) "country"
  19. set tg(28) "trace"
  20. set tg(29) "asn"
  21. set tg(30) "ns"
  22. set tg(31) "lagcheck"
  23. set tg(35) "ping"
  24. bind pub - ${bt(char)}${bt(trig)}${tg(26)} pub:host
  25. bind pub - ${bt(char)}${bt(trig)}${tg(27)} pub:country
  26. bind pub - ${bt(char)}${bt(trig)}${tg(28)} pub:trace
  27. bind pub - ${bt(char)}${bt(trig)}${tg(29)} pub:asn
  28. bind pub - ${bt(char)}${bt(trig)}${tg(30)} dns:ns
  29. bind pub - ${bt(char)}${bt(trig)}${tg(31)} pub:lag:check
  30. bind pub - ${bt(char)}${bt(trig)}${tg(35)} pub:ping
  31. bind pub - ${bt(char)}${tg(all)}${tg(26)} pub:host
  32. bind pub - ${bt(char)}${tg(all)}${tg(27)} pub:country
  33. bind pub - ${bt(char)}${tg(all)}${tg(28)} pub:trace
  34. bind pub - ${bt(char)}${tg(all)}${tg(29)} pub:asn
  35. bind pub - ${bt(char)}${tg(all)}${tg(30)} dns:ns
  36. bind pub - ${bt(char)}${tg(all)}${tg(31)} pub:lag:check
  37. bind pub - ${bt(char)}${tg(all)}${tg(35)} pub:ping
  38. bind raw - 391 raw:check:lag
  39. proc pub:asn {n u h c txt} {
  40. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  41. set host [string trim [lindex [split $txt] 0]]
  42. if {[regexp {^[a-zA-Z]} $host]} { putserv "PRIVMSG $c :\002(\002ASN\002):\002 Please use IP format." ; return 0 } else {
  43.     if {![catch {set tmp [exec whois -h whois.cymru.com $host]} error]} {
  44.         foreach line [split $error "\n"] {
  45.             if {[regexp -- {^[0-9](.*)} $line line]} {
  46.                 regsub -all { } $line {} line
  47.                 set id [lindex [split $line "|"] 0]
  48.                 set ip [lindex [split $line "|"] 1]
  49.                 set company [lindex [split $line "|"] 2]
  50.                 putserv "PRIVMSG $c :\002(\002ASN:$id\002):\002 IP: \002$ip\002. Company: \002$company\002." }
  51.             }
  52.         } else { putserv "PRIVMSG $c :error: $error" }
  53. }
  54. }
  55.  
  56. proc pub:country {n u h c t} {
  57. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  58.   global country symbol
  59.   if {$t == "" || [llength $t] > 1} {
  60.     putserv "PRIVMSG $c :invalid syntax"
  61.     return 0
  62.   }
  63.   set this [lsearch -exact $symbol [string trimleft [string toupper $t] .]]
  64.   if {$this > -1} {
  65.     putserv "PRIVMSG $c :Country name for .[string trimleft [string toupper $t] .] is [lindex $country $this]"
  66.     return 1
  67.   } else {
  68.     putserv "PRIVMSG $c :nothing found for .[string trimleft [string toupper $t] .]"
  69.     return 0
  70.   }
  71. }
  72.  
  73. set country {
  74. "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"
  75. "Bosnia and Herzegovina" "Barbados" "Bangladesh" "Belgium" "Burkina Faso" "Bulgaria" "Bahrain" "Burundi" "Benin" "Bermuda" "Brunei Darussalam" "Bolivia" "Brazil" "Bahamas" "Bhutan" "Bouvet Island" "Botswana" "Belarus" "Belize"
  76. "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"
  77. "East Germany" "Germany" "Djibouti" "Denmark" "Dominica" "Dominican Republic" "Algeria"
  78. "Ecuador" "Estonia" "Egypt" "Western Sahara" "Eritrea" "Spain" "Ethiopia" "European Union"
  79. "Finland" "Fiji" "Falkland Islands" "Federated States of Micronesia" "Faroe Islands" "France"
  80. "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"
  81. "Hong Kong" "Heard Island and McDonald Islands" "Honduras" "Croatia" "Haiti" "Hungary"
  82. "Indonesia" "Ireland" "Israel" "Isle of Man" "India" "British Indian Ocean Territory" "Iraq" "Iran" "Iceland" "Italy"
  83. "Jersey" "Jamaica" "Jordan" "Japan"
  84. "Kenya" "Kyrgyzstan" "Cambodia" "Kiribati" "Comoros" "Saint Kitts and Nevis" "Democratic People's Republic of Korea" "Republic of Korea" "Kuwait" "Cayman Islands" "Kazakhstan"
  85. "Laos" "Lebanon" "Saint Lucia" "Liechtenstein" "Sri Lanka" "Liberia" "Lesotho" "Lithuania" "Luxembourg" "Latvia" "Libya"
  86. "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"
  87. "Namibia" "New Caledonia" "Niger" "Norfolk Island" "Nigeria" "Nicaragua" "Netherlands" "Norway" "Nepal" "Nauru" "Niue" "New Zealand"
  88. "Oman"
  89. "Panama" "Peru" "French Polynesia" "Papua New Guinea" "Philippines" "Pakistan" "Poland" "Saint-Pierre and Miquelon" "Pitcairn Islands" "Puerto Rico" "Palestinian territories" "Portugal" "Palau" "Paraguay"
  90. "Qatar"
  91. "Reunion" "Romania" "Serbia" "Russia" "Rwanda"
  92. "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"
  93. "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"
  94. "Ukraine" "Uganda" "United Kingdom" "United States of America" "Uruguay" "Uzbekistan"
  95. "Vatican City" "Saint Vincent and the Grenadines" "Venezuela" "British Virgin Islands" "U.S. Virgin Islands" "Vietnam" "Vanuatu"
  96. "Wallis and Futuna" "Samoa, Formerly Western Samoa"
  97. "Yemen" "Mayotte"
  98. "South Africa" "Zambia" "Zimbabwe"
  99. "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"
  100. }
  101.  
  102. set symbol {
  103. AC AD AE AF AG AI AL AM AN AO AQ AR AS AT AU AW AX AZ
  104. BA BB BD BE BF BG BH BI BJ BM BN BO BR BS BT BV BW BY BZ
  105. CA CC CD CF CG CH CI CK CL CM CN CO CR CS CU CV CX CY CZ CO.UK
  106. DD DE DJ DK DM DO DZ
  107. EC EE EG EH ER ES ET EU
  108. FI FJ FK FM FO FR
  109. GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY
  110. HK HM HN HR HT NU
  111. ID IE IL IM IN IO IQ IR IS IT
  112. JE JM JO JP
  113. KE KG KH KI KM KN KP KR KW KY KZ
  114. LA LB LC LI LK LR LS LT LU LV LY
  115. MA MC MD ME MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ
  116. NA NC NE NF NG NI NL NO NP NR NU NZ
  117. OM
  118. PA PE PF PG PH PK PL PM PN PR PS PT PW PY
  119. QA
  120. RE RO RS RU RW
  121. SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR ST SU SV SY SZ
  122. TC TD TF TG TH TJ TK TL TM TN TO TP TR TT TV TW TZ
  123. UA UG UK US UY UZ
  124. VA VC VE VG VI VN VU
  125. WF WS
  126. YE YT
  127. ZA ZM ZW
  128. AERO ASIA BIZ CAT COM COOP EDU GOV INFO INT JOBS MIL MOBI MUSEUM NAME NET ORG PRO TEL TRAVEL XXX
  129. }
  130. proc pub:trace {n u h c txt} {
  131. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  132. if {![catch {set tmp [exec dig -x $txt +trace]} error]} {
  133. putserv "PRIVMSG $c :\002(\002TRACE\002):\002 Requesting information, please wait..."
  134. set out "empty"
  135. foreach line [split $tmp "\n"] {
  136. if {[string match "*;;*" $line]} { continue }
  137. if {[string match "*servers.*." $line]} { continue }
  138. if {[string match "*PTR*" $line]} { continue }
  139. if {[string match "*arin.net." $line]} { continue }
  140. if {[string match "*authdns*" $line]} { continue }
  141. if {[string match "sec*.*" $line]} { continue }
  142. if {[string match "*apnic.net." $line]} { continue }
  143. if {[string match "*lacnic.net." $line]} { continue }
  144. if {[string match "*be*reached*" $line]} { putserv "PRIVMSG $c :\002(\002TRACE\002):\002 No servers could be reached!" ; return 0 }
  145. if {[string match "*NS*" $line]} { append out "[lindex $line 4] " }
  146. }
  147. if {[string match "empty" $out]} { putserv "PRIVMSG $c :\002(\002TRACE\002):\002 Nothing found."; return }
  148. putserv "PRIVMSG $c :\002(\002TRACE\002):\002 IP: ($txt) $out"
  149. } else {
  150. putserv "PRIVMSG $c :\002(\002TRACE\002):\002 Timeout."
  151. }
  152.  
  153. }
  154.  
  155. proc pub:host {n u h c txt} {
  156. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  157.     set host [string trim [lindex [split $txt] 0]]
  158.     if {[string length $host] < 2} { putserv "PRIVMSG $c :try a valid host" ; return }
  159.     if {[string length $host] > 65} { putserv "PRIVMSG $c :domain too long..less then 63 letters and numbers..idiot. example: 63lettersornumbers.com"; return }
  160.         if {![catch {set tmp [exec host -tA $host]} error]} { dns:v4 $host $c } else { putserv "PRIVMSG $c :\002(\002DNS\002):\002 No A Record." }
  161.         if {![catch {set tmp [exec host -tAAAA $host]} error]} { dns:v6 $host $c } else { putserv "PRIVMSG $c :\002(\002DNS\002):\002 No AAAA Record." }
  162. }
  163.  
  164. proc dns:v6 {host chan} {
  165. if {![catch {set data [exec host -tAAAA $host]} error]} {
  166.     foreach line [split $data "\n"] {
  167.         if {[string match "*has no*" $line]} {
  168.             putserv "PRIVMSG $chan :\002(\002DNS\002):\002 No AAAA record found."
  169.         return
  170.         }
  171.     if {[regexp {(.*) has IPv6 address (.*)} $line match rHost6 output]} {
  172.         putserv "PRIVMSG $chan :\002(\002DNS\002):\002 \002$rHost6\002 resolves to: \002$output\002, reverse: \002[dns:rv6 $output]"
  173.     }
  174.     if {[regexp {(.*) domain name pointer (.*)} $line match rHost6 output]} {
  175.         putserv "PRIVMSG $chan :\002(\002DNS\002):\002 \002$rHost6\002 resolves to: \002$output\002"
  176.     }
  177.       }
  178.    }
  179. }
  180. proc dns:rv6 {host} {
  181. if {![catch {set result [exec host -tAAAA $host]} error]} {
  182.     foreach line [split $result "\n"] {
  183.         if {[regexp {(.*) domain name pointer (.*)} $line found host result]} { return $result }
  184.     }
  185.     } else { return "\002none!" }
  186. }
  187.  
  188. proc dns:ns {n u h c t} {
  189. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  190. set host [lindex $t 0]
  191. if {![catch {set data [exec host -tNS $host]} error]} {
  192.     foreach line [split $data "\n"] {
  193.           if {[regexp {(.*) name server (.*)} $line match rHost4 output]} {
  194.             putserv "PRIVMSG $c :\002(\002NS\002):\002 \002$rHost4\002 NS->: \002$output\002"
  195.           }
  196.     }
  197. }
  198.           if {[string match "*NXDOMAIN*" $error]} {
  199.             putserv "PRIVMSG $c :\002(\002NS\002):\002 No NS record found."
  200.           return
  201.           }
  202. }
  203.  
  204. proc dns:v4 {host chan} {
  205. if {![catch {set data [exec host -tA $host]} error]} {
  206.     foreach line [split $data "\n"] {
  207.           if {[string match "*has no*" $line]} {
  208.             putserv "PRIVMSG $chan :\002(\002DNS\002):\002 No A record found."
  209.           return
  210.           }
  211.           if {[regexp {(.*) has address (.*)} $line match rHost4 output]} {
  212.             putserv "PRIVMSG $chan :\002(\002DNS\002):\002 \002$rHost4\002 resolves to: \002$output\002, reverse: \002[dns:rv4 $output]"
  213.           }
  214.     }
  215. }
  216. }
  217. proc dns:rv4 {host} {
  218. if {![catch {set result [exec host -tPTR $host]} error]} {
  219.     foreach line [split $result "\n"] {
  220.         if {[regexp {(.*) domain name pointer (.*)} $line found host result]} { return $result }
  221.     }
  222.     } else { return "\002none!" }
  223. }
  224.  
  225. proc flood {uhost} {
  226.  global lastbind dns_f dns
  227.  set a [lindex [split $dns(flood) :] 0] ; set b [lindex [split $dns(flood) :] 1]
  228.  if {[info exists dns_f($uhost)]} {
  229.   incr dns_f($uhost) 1
  230.   if {$dns_f($uhost) > $a} {
  231.    newignore *!*@${uhost} BOXINFO Flood $dns(ignore)
  232.    return 1
  233.   }
  234.  } {set dns_f($uhost) 1}
  235.  if {![string match "*unset dns_f($uhost)*" [utimers]]} {
  236.   utimer $b "catch {unset dns_f($uhost)}"
  237.  } ; return 0
  238. }
  239. proc pub:lag:check {nick host hand chan test} {
  240.                 set ::lag "[clock clicks]";set ::lagchan $chan
  241.                 putquick "TIME"
  242.         }
  243. proc raw:check:lag {from key text} {
  244.         putmsg $::lagchan "\273\273 Current Networklag: [expr (([clock clicks] - $::lag)/2)/1000.] ms"
  245.         unset ::lagchan;unset ::lag
  246. }
  247.  
  248. proc pub:ping {n u h c t} {
  249. if {[flood [string range $u [expr [string last @ $u]+1] e]]} {return 0}
  250. if {[string match "*:*" $t]} { set pingexec "/bin/ping6" } else { set pingexec "/bin/ping" }
  251. if {![catch {set data [exec $pingexec -c4 $t]} error]} {
  252.     foreach line [split $data "\n"] {
  253.         if {[string match "*64 bytes from*" $line]} {
  254.         regexp -- {from (.*?): } $line -> ip
  255.         regexp -- {time=(.*?)ms} $line -> tim
  256.         if {[string match "*packets transmitted*" $line]} {
  257.             set footer "$line"
  258.         }
  259. }
  260. }
  261.         putserv "PRIVMSG $c :\002(\002IP\002):\002 $ip \002${tim}\002ms"
  262. }
  263.     foreach l [split $error "\n"] {
  264.         if {[string match "*packet loss*" $l]} { putserv "PRIVMSG $c :\002(\002IP\002):\002 stats: $l" }
  265.     }
  266. }
  267. putlog "dns.tcl loaded."
  268.  
  269. set portcheck_setting(flag) "-|-"
  270. set portcheck_setting(cmd_pub) ".port"
  271. set portcheck_setting(cmd_dcc) "portcheck"
  272. set portcheck_setting(read) 1
  273. set portcheck_setting(onjoin) 0
  274. set portcheck_setting(ports) "1080 21 23"
  275. set portcheck_setting(exemptflag) "+E"
  276. set portcheck_setting(autoban_svr) 0
  277. set portcheck_setting(autoban_list) 0
  278. set portcheck_setting(global) 0
  279. set portcheck_setting(bantime) 5
  280. set portcheck_setting(onotice) 1
  281. set portcheck_setting(bold) 1
  282. set portcheck_setting(PORTCHECK:) 1
  283. bind pub $portcheck_setting(flag) $portcheck_setting(cmd_pub) portcheck_scan_pub
  284. bind dcc $portcheck_setting(flag) $portcheck_setting(cmd_dcc) portcheck_scan_dcc
  285. bind join - * portcheck_onjoin_scan
  286. setudef flag portcheck
  287.  
  288. proc portcheck_dopre {} {
  289.     global portcheck_setting
  290.     if {!$portcheck_setting(PORTCHECK:)} {
  291.         return ""
  292.     } elseif {!$portcheck_setting(bold)} {
  293.         return "PORTCHECK: "
  294.     } else {
  295.         return "\002PORTCHECK:\002 "
  296.     }
  297. }
  298. proc portcheck_onjoin_scan {nick uhost hand chan} {
  299.     global portcheck_setting portcheck_chans
  300.     if {($portcheck_setting(onjoin)) && ($portcheck_setting(ports) != "") && (![matchattr $hand $portcheck_setting(exemptflag)])} {
  301.         foreach i [channel info $chan] {
  302.             if {([string match "+portcheck" $i]) && ([botisop $chan])} {
  303.                 set host [lindex [split $uhost @] 1]
  304.                 foreach p $portcheck_setting(ports) {
  305.                     if {![catch {set sock [socket -async $host $p]} error]} {
  306.                         set timerid [utimer 15 [list portcheck_timeout_join $sock]]
  307.                         fileevent $sock writable [list portcheck_connected_join $nick $chan $sock $host $p $timerid]
  308.                     }
  309.                 }
  310.                 break
  311.             }
  312.         }
  313.     }
  314. }
  315. proc portcheck_scan_pub {nick uhost hand chan text} {
  316.     global portcheck_setting
  317.     set host [lindex $text 0]
  318.     set port [lindex $text 1]
  319.     if {$port == ""} {
  320. #       putquick "NOTICE $nick :Usage: $portcheck_setting(cmd_pub) <host> <port>"
  321.         putquick "PRIVMSG $chan :Usage: $portcheck_setting(cmd_pub) <host> <port>"
  322.     } else {
  323.         if {[catch {set sock [socket -async $host $port]} error]} {
  324.             putquick "PRIVMSG $chan :\002(\002Port\002)\002: Connection to $host:$port was motherfucking refused "
  325.         } else {
  326.             set timerid [utimer 15 [list portcheck_timeout_pub $chan $sock $host $port]]
  327.             fileevent $sock writable [list portcheck_connected_pub $chan $sock $host $port $timerid]
  328.         }
  329.     }
  330. }
  331. proc portcheck_scan_dcc {hand idx text} {
  332.     global portcheck_setting
  333.     set host [lindex $text 0]
  334.     set port [lindex $text 1]
  335.     if {$port == ""} {
  336.         putdcc $idx "[portcheck_dopre]Usage: .$portcheck_setting(cmd_dcc) <host> <port>"
  337.     } else {
  338.         if {[catch {set sock [socket -async $host $port]} error]} {
  339.             putdcc $idx "[portcheck_dopre]Connection to $host \($port\) was refused "
  340.         } else {
  341.             set timerid [utimer 15 [list portcheck_timeout $idx $sock $host $port]]
  342.             fileevent $sock writable [list portcheck_connected $idx $sock $host $port $timerid]
  343.         }
  344.     }
  345. }
  346. proc portcheck_connected {idx sock host port timerid} {
  347.     killutimer $timerid
  348.     if {[set error [fconfigure $sock -error]] != ""} {
  349.         close $sock
  350.         putdcc $idx "[portcheck_dopre]Connection to $host \($port\) failed \([string totitle $error]\)"
  351.     } else {
  352.         fileevent $sock writable {}
  353.         fileevent $sock readable [list portcheck_read $idx $sock $host $port]
  354.         putdcc $idx "[portcheck_dopre]Connection to $host \($port\) accepted "
  355.     }
  356. }
  357. proc portcheck_timeout {idx sock host port} {
  358.     close $sock
  359.     putdcc $idx "[portcheck_dopre]Connection to $host \($port\) timed out "
  360. }
  361. proc portcheck_read {idx sock host port} {
  362.     global portcheck_setting
  363.     if {$portcheck_setting(read)} {
  364.         if {[gets $sock read] == -1} {
  365.             putdcc $idx "[portcheck_dopre]EOF On Connection To $host \($port\). Socket Closed."
  366.             close $sock
  367.         } else {
  368.             putdcc $idx "[portcheck_dopre]$host \($port\) > $read"
  369.         }
  370.     } else {
  371.         close $sock
  372.     }
  373. }
  374. proc portcheck_connected_pub {chan sock host port timerid} {
  375.     killutimer $timerid
  376.     if {[set error [fconfigure $sock -error]] != ""} {
  377.         close $sock
  378.         putquick "PRIVMSG $chan :\002(\002Port\002)\002: Connection to $host:$port motherfucking failed. \([string totitle $error]\)"
  379.     } else {
  380.         fileevent $sock writable {}
  381.         fileevent $sock readable [list portcheck_read_pub $chan $sock $host $port]
  382.         putquick "PRIVMSG $chan :\002(\002Port\002)\002: Connection to $host:$port accepted. :D "
  383.     }
  384. }
  385. proc portcheck_timeout_pub {chan sock host port} {
  386.     close $sock
  387.     putquick "PRIVMSG $chan :\002(\002Port\002)\002: Connection to $host:$port timed out. :-( "
  388. }
  389. proc portcheck_connected_join {nick chan sock host port timerid} {
  390.     global portcheck_setting botnick
  391.     killutimer $timerid
  392.     if {[set error [fconfigure $sock -error]] != ""} {
  393.         close $sock
  394.     } else {
  395.         fileevent $sock writable {}
  396.         fileevent $sock readable [list portcheck_read_join $sock]
  397.         if {$portcheck_setting(onotice)} {
  398.             foreach i [chanlist $chan] {
  399.                 if {([isop $i $chan]) && ($i != $botnick)} {
  400.                     putserv "NOTICE $i :Port $port was found open on $nick's host. \($host\)"
  401.                 }
  402.             }
  403.         }
  404.         if {$portcheck_setting(autoban_svr)} {
  405.             putserv "MODE $chan +b *!*@$host"
  406.             putserv "KICK $chan $nick :One of the ports open on your host is banned."
  407.             timer $portcheck_setting(bantime) [list portcheck_unsvrban $chan $host]
  408.         } elseif {$portcheck_setting(autoban_list)} {
  409.             if {$portcheck_setting(global)} {
  410.                 newban *!*@$host PortCheck "One of the ports open on your machine is banned." $portcheck_setting(bantime)
  411.             } else {
  412.                 newchanban $chan *!*@$host PortCheck "One of the ports open on your machine is banned." $portcheck_setting(bantime)
  413.             }
  414.         }
  415.     }
  416. }
  417. proc portcheck_timeout_join {sock} {
  418.     close $sock
  419. }
  420. proc portcheck_read_join {sock} {
  421.     close $sock
  422. }
  423. proc portcheck_read_pub {sock} {
  424.     global portcheck_setting
  425.     if {!$portcheck_setting(read)} {
  426.         close $sock
  427.     } elseif {[gets $sock read] == -1} {
  428.         putquick "PRIVMSG $chan :\002(\002Port\002)\002: EOF On Connection To $host:$port. Socket Closed."
  429.         close $sock
  430.     }
  431. }
  432. proc portcheck_unsvrban {chan host} {
  433.     putserv "MODE $chan -b *!*@$host"
  434. }
  435. putlog "port.tcl loaded."
  436.  
  437. bind pub - .os oscheck
  438. proc oscheck {nick host handle chan text} {
  439.     set server [lindex $text 0]
  440.     set port 80
  441.     set x 1
  442.     set sock [socket $server $port]
  443.     puts $sock "GET / HTTP/1.0"
  444.     puts $sock "User.Agent:Mozilla"
  445.     puts $sock "Host: $server"
  446.     puts $sock ""
  447.     flush $sock
  448.     while {$x < 10} {
  449.     gets $sock line
  450.         if {[string match "*erver: *" $line]} {
  451.             putserv "PRIVMSG $chan :$line"
  452.         }
  453.         if {[string match "*ate: *" $line]} {
  454.             putserv "PRIVMSG $chan :$line"
  455.         }
  456.         incr x
  457.     }
  458.     close $sock
  459. }
  460. putlog "os.tcl loaded."
  461.  
  462. bind pub - .nmap port_scan
  463. proc port_scan {nick uhost handle chan text} {
  464. if {[flood [string range $uhost [expr [string last @ $uhost]+1] e]]} {return 0}
  465. set h [lindex $text 0]; set flags [lrange $text 1 end]; set nmap [exec which nmap]; set f ""
  466. 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 " } } } }
  467. putserv "PRIVMSG $chan :\002(\002nmap\002)\002: $h: (\002TCP\002) $f"
  468. }
  469.  
  470. bind pub - .nmap6 port_scan6
  471. proc port_scan6 {nick uhost handle chan text} {
  472. if {[flood [string range $uhost [expr [string last @ $uhost]+1] e]]} {return 0}
  473. set h [lindex $text 0]; set flags [lrange $text 1 end]; set nmap [exec which nmap]; set f ""
  474. if {![catch {set data [exec $nmap -6 \-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 " } } } }
  475. putserv "PRIVMSG $chan :\002(\002nmap6\002)\002: $h: (\002TCP\002) $f"
  476. }
  477. putlog "nmap.tcl loaded."
  478.  
  479. bind pub * .ip fetch:geo
  480. proc fetch:geo {nick uhost hand chan text} {
  481.    if {[scan $text {%s} lookup] != 1} {
  482.       puthelp "PRIVMSG $chan :Error, syntax is: .ip 127.0.0.1"
  483.       return
  484.    }
  485.    if {![regexp {([0-9]+\.)([0-9]+\.)([0-9]+\.)([0-9]+)} $lookup]} {
  486.       puthelp "PRIVMSG $chan :Error, the IP you mentioned is not valid."
  487.       return
  488.    }
  489.    catch {set http [::http::geturl http://ipinfo.io/$lookup/json -timeout 6000]} error
  490.    set data [::http::data $http]
  491.    set json [::json::json2dict $data]
  492.    ::http::cleanup $http
  493.    set keys [dict keys $json]
  494.    foreach ele {ip hostname city region country loc postal phone org} {
  495.       set $ele [expr {[lsearch $keys $ele] > -1 ? [dict get $json $ele] : "n/a"}]
  496.    }
  497.    puthelp "PRIVMSG $chan :\002(Geo):\002 IP:\002 $ip \002- Hostname:\002 $hostname \002- City:\002 $city \002- Region:\002 $region \002- Country:\002 $country \002- Location:\002 $loc \002- Organization:\002 $org \002"
  498. }
  499. putlog "ipinfo.tcl loaded."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement