-
Notifications
You must be signed in to change notification settings - Fork 2
/
tcpcheck.tcl
43 lines (37 loc) · 1.16 KB
/
tcpcheck.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# simple tcp client
# (c)2014 cr0n
set vers "0.1"
set host "your_ip"
set port "your_port"
setudef flag trollenv
bind pub - !trollenv pub:get_data
proc pub:get_data {n u h c a} {
if {![channel get $c trollenv]} { return }
set data [int:get_data]
if {[llength $data] == 1} {
switch [lindex $data 0] {
e_socks {putserv "PRIVMSG $c :error: timeout"}
e_parse {putserv "PRIVMSG $c :error: crappy data"}
default {putserv "PRIVMSG $c :error: wtf.."}
}
} else {
putserv "PRIVMSG $c :geiger counter: [lindex $data 0] cpm"
putserv "PRIVMSG $c :temperature: [format "%.1f" [lindex $data 1]]°C"
}
}
proc int:get_data {} {
global host port
set ret {}
set sock [socket -async $host $port]
if {[catch {gets $sock line1}] || [catch {gets $sock line2}]} {
lappend ret "e_socks"
} else {
if {[regexp {^(\d+)$} [string trim $line1] -> count] && [regexp {^(\d+(?:[.,]\d+)?)$} [string trim $line2] -> temp]} {
lappend ret $count $temp
} else {
lappend ret "e_parse"
}
}
return $ret
}
putlog "TCP Check v$vers successfully loaded."