source: trollforge/lenny/proxycheck.tcl @ 198

Revision 54, 1.4 KB checked in by lenny, 8 years ago (diff)
Line 
1#!/usr/local/bin/tclsh
2
3package require http
4
5set p_ip ""
6set p_hd ""
7
8proc p_close {channel} {
9
10        puts $channel ""
11        close $channel
12}
13
14proc p_read {channel} {
15
16        global p_hd
17
18        append p_hd [read $channel]
19}
20
21proc p_accept {channel clientaddr clientport} {
22
23        global p_ip p_hd
24       
25        set p_ip $clientaddr
26        set p_hd ""
27       
28        fconfigure $channel -blocking false -buffering none
29        fileevent $channel readable "p_read $channel"
30        after 9000 "p_close $channel"
31}
32
33proc p_check {host port} {
34
35        global p_ip p_hd
36
37        set p_ip ""
38        set p_hd ""
39
40        set schannel [socket -server p_accept 9900]
41       
42        ::http::config -proxyhost $host -proxyport $port
43       
44        set query [::http::formatQuery \
45                sid 10 \
46                pid 20 \
47        ]
48
49        catch {
50       
51                set q [::http::geturl "http://mondogrigio.cjb.net:9900/" \
52                        -query $query \
53                        -timeout 10000 \
54                ]
55               
56                ::http::cleanup $q
57        }
58       
59        after 10000
60       
61        ::http::config -proxyhost "" -proxyport ""
62        close $schannel
63
64        puts "Proxy ip: $p_ip"
65        puts ----
66        puts $p_hd
67        puts ----
68}
69
70set q [::http::geturl "http://www.proxy4free.com/page3.html"]
71set p [::http::data $q]
72::http::cleanup $q
73
74regsub -all {<[^>]*>} $p {} p
75
76while {
77        [
78                regexp -indices \
79                {([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)[^0-9]+([0-9]+)} \
80                $p m hosti porti \
81        ]
82} {
83
84        set host [string range $p {expand}$hosti]
85        set port [string range $p {expand}$porti]
86
87        puts "Test: $host $port"
88        puts ----
89       
90        p_check $host $port
91
92        set p [string range $p [expr [lindex $m 1] + 1] end]
93}
Note: See TracBrowser for help on using the repository browser.