This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Sockets

Old posts that have not been replied to for several years.
Locked
G
Guest

Post by Guest »

Hi, i am trying to make a script that will
tell me the webserver software of a site
i put putserv "PRIVMSG $chan :$i" in so i could see what was going on. So i did .http eggdrop.org and it said to the channel:

HTTP/1.1 200 OK
Date: Wed, 14 Nov 2001 22:49:14 GMT
Server: Apache/1.3.14
Connection: close
Content-Type: text/html

i wanted it to tell me the text between Server: and Connection: but it only writes the above to the channel and not the text between the two.

Code:

bind pub - http http
proc http {nick host hand chan arg} {
set site "[lindex $arg 0]"
set sock [socket $site 80]
puts $sock "HEAD / HTTP/1.0n"
flush $sock
set test [read $sock]
close $sock
set test [split $test n]

foreach i $test {
putserv "PRIVMSG $chan :$i"
if {[string first Server $i] != -1} {
set 1 [expr [string first : $i] +2]
set 2 [expr [string first Connection: $i] -1]
set result [string range $i $1 $2]
putserv "PRIVMSG $chan :$result"
}
}
}

whats wrong with this?
Thanks


<font size=-1>[ This Message was edited by: PnT on 2001-11-14 18:01 ]</font>
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Don't use list commands on a string (lindex $arg). Also, there's a reason they're called variable *names* and not variable numbers. Don't use confusing variable names like "1" and "2" that just makes the code harder to understand.

More to the point at hand, you split $test up into a list of lines, and examine each line, one at a time. So of course you will never find "Server" and "Connection:" in the same element.. they're on separate lines.
Locked