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.

Socket problem ..

Old posts that have not been replied to for several years.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Socket problem ..

Post by Ofloo »

Code: Select all

proc proxy_scan {nick host} {
  global proxy
  foreach port $proxy(port) {
    catch {socket $host $port} proxy(sock)
    catch {close $proxy(sock)}
    if {[string match -nocase "sock?" $proxy(sock)]} {
      operwall "Possible open proxy found on $host $port \($nick\)"
    }
  }
}
it works but after a while it freezes .. and i have no clue why that could be .. someone ??
XplaiN but think of me as stupid
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

maybe adding a timeout ?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Code: Select all

proc proxy_scan {nick host} {
  global proxy
  foreach port $proxy(port) {
    catch {socket -async $host $port} proxy(socket)
    if {[string match -nocase "sock?" $proxy(socket)] && ![string match -nocase {} $proxy(socket)]} {
      fconfigure $proxy(socket) -blocking 0
      fileevent $proxy(socket) writable [open_sock $nick $proxy(socket) $host $port]
      close $proxy(socket)
    }
  }
}

proc open_sock {nick socket host port} {
  operwall "Possible open proxy found on $host $port \($nick\)"
}
i have tryed something simular looking for a way to add a timeout would be great full if u could set me on the right track ..

thing is if i use -async everything is a socket if i don't well then it works but .. it freezes after a while

and async is worse it says that everything has an open port .. i know u have to check for writeable socket but .. how do you do that ... the script with -async above is not working
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Now i am stuck no more ideas ..
error :(
couldn't open "../logs/service.log": too many open files

Code: Select all

proc proxy_scan {nick host} {
  global proxy
  foreach port $proxy(port) {
    catch {socket -async $host $port} proxy(socket)
    if {[string match -nocase "sock?" $proxy(socket)] && [string match -nocase {} $proxy(socket)]} {
      fileevent $proxy(socket) readable [list open_sock $nick $proxy(socket) $host $port]
    }
  }
}

proc open_sock {nick socket host port} {
  global proxy
  catch {
    set proxy(error) [fconfigure $socket -error]
    close $socket
  } proxy(error)
  eval report_sock [list $nick $host $port]
}

proc report_sock {nick host port} {
  if {[string match -nocase {} $proxy(error)]} {
    operwall "Possible open proxy found on $host $port \($nick\)"
  }
}
XplaiN but think of me as stupid
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

couldn't open "../logs/service.log": too many open files
you have opened too many files allready, they might have not been closed when you experimented previously or they are still not close correctly.

i didnt work with sockets yet so i cant help you except to tell you to check back the manual :P
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

I did to technical also checked the forum the thing is its not for a channel its to check an entire irc server i am writing a complete service in tcl the thing is there is something wrong with fileevent it takes to long before it has checked it almost like it is waiting untill it becomes writable do you got a solution on that .. i mean something that times it out or closes to socket i can't use utimer or any other eggdrop commands sinds its a socket bot that emulates a server and not an eggdrop
XplaiN but think of me as stupid
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Using socket -async, fconfigure, fileevent is the right way. For timers use the after command. Also, you're using fileevent readable, when it should really be writable.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

sorry tryed bot .. readable and writeable ..

i know about after the thing is havn't figured out how to use it yet i must be doing something wrong cause the socket connects and remains open i set up netcat on my host and it just stays open doing nothing ..
XplaiN but think of me as stupid
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

<snip...>

n/m..
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Well the reason it's probably not working is your if command. I mean take a look at it, for a minute. In english it says, "if $proxy(socket) matches "sock?" AND $proxy(socket) matches {}, then do this". It's never going to match both of those at the same time.

Also it's really sloppy to use catch like that. You should have it in an if statement, because it returns 1 when there's an error, and 0 when there isn't one. Then you don't need that string match at all.

By the way, hopefully you are passing it ip addresses and not hosts (as the variable name implies) because tcl does *not* do async dns lookups.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Oh ya one more thing, the after command is used like the utimer command, except you give it milliseconds instead of seconds. set timerid [after 5000 myproc], waits 5 seconds (5000 ms). To kill it, do "after cancel $timerid"
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

ic ur right but still doesn't work also changed the vars below cause they overwrited them selfs forgot about that !

the connection remains open and still doesn't close i allready tryed to add a flush infront so it can become writeable but it seems that this doesn't work either ..

Code: Select all

proc proxy_scan {nick host} {
  global proxy
  foreach port $proxy(port) {
    catch {socket -async $host $port} proxy(socket)
    if {[string match -nocase "sock?" $proxy(socket)] && ![string match -nocase {} $proxy(socket)]} {
      flush $proxy(socket)
      fileevent $proxy(socket) writable [list open_sock $nick $proxy(socket) $host $port]
    }
  }
}

proc open_sock {nick socket host port} {
  catch {
    set error [fconfigure $socket -error]
    close $socket
  } errors
  eval report_sock [list $nick $host $port $error]
}

proc report_sock {nick host port error} {
  if {[string match -nocase {} $error]} {
    operwall "Possible open proxy found on $host $port \($nick\)"
  }
}
By the way, hopefully you are passing it ip addresses and not hosts (as the variable name implies) because tcl does *not* do async dns lookups.
no didn't know that i used there hosts thing is it does connect tho i can see it on netcat it opens but thats it so it connects but does not close netcat will only close the sock if it is dropped.

so if ur question is is it connecting yes .. tnx for the tip tho ill add it once i get it right ..

Code: Select all

#!/usr/bin/tclsh

set proxy(port) "1080 1081 3380 3381"

proc proxy_scan {nick host} {
  global proxy
  foreach port $proxy(port) {
    catch {socket -async $host $port} proxy(socket)
    if {[string match -nocase "sock?" $proxy(socket)] && ![string match -nocase {} $proxy(socket)]} {
      flush $proxy(socket)
      fileevent $proxy(socket) writable [list open_sock $nick $proxy(socket) $host $port]
    }
  }
}

proc open_sock {nick socket host port} {
#  catch {
    set error [fconfigure $socket -error]
    close $socket
#  } errors
  eval report_sock [list $nick $host $port $error]
}

proc report_sock {nick host port error} {
  if {[string match -nocase {} $error]} {
    puts "Possible open proxy found on $host $port \($nick\)"
  }
}


proxy_scan somenick [lindex $argv 0]
tryed that in shell script doesn't realy mather .. if i use numeric ips ..
XplaiN but think of me as stupid
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Get rid of the string matches and the flush.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Also, if you're testing in the shell, you need something like vwait so that it waits around. Otherwise it will exit right away.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Doesn't mather allready tryed :( i added the flush to make it writable incase tcl made it readable

cause ive noticed if u get data out a channel and then wana send data that this is not possible .. so by applying a flush it is .. but also tryed without and with .. so .. ive been trying various combinations seems like i can't find a solution can't find the error ?? where would i add vwait ? and wait on what variable to be set ..?
Last edited by Ofloo on Sat Feb 28, 2004 4:08 pm, edited 1 time in total.
XplaiN but think of me as stupid
Locked