Version 0 of ipscan

Updated 2008-05-02 20:20:01 by KL
   proc scan_ip {start_ip end_ip} {

global globals set curr_ip 192.168.0.$start_ip set end_ip_section 192.168.0.$end_ip

  while {$curr_ip != $end_ip_section} {
    #open the whole bunch of sockets (normaly 255)
    if {![catch {set sock [socket  -async $curr_ip $globals(client_server_port)]}]} {
      fconfigure $sock -blocking 0 -buffering line
      append ip_list "$sock $curr_ip "  
    puts "testing:$curr_ip"
    }
    incr start_ip
    set curr_ip 192.168.0.$start_ip
  }

after 100 #check the successfully opened sockets if there is an server behind foreach {sock curr_ip} $ip_list { set test ""

  catch {set test [gets $sock] }
   if {$test == "SERVER_OK" } { 
   set ret_ip $curr_ip

# after 100

   puts "SUCCESS: Found server at: $curr_ip"
   break
   }

#after 5 } #close sockets again foreach {sock curr_ip} $ip_list { close $sock } }

proc Configure_Server_Client {sock addr port} {

    global globals

# puts "socket_list: file channel sock*"

    # Record the client's information
    fconfigure $sock -blocking 0 -buffering line
    # Set up a event if data is present at admin socket
    if {[catch {puts $sock "SERVER_OK"}]} {
    puts "remote gui socket not available anymore closing sock: $sock"
    close $sock
    return
    }

##for this check all is done I close the socket again close $sock puts "successfully etablished connection to client" exit } if {$argc != 1} { puts "usage:file tail $argv0 <server|client>" exit } set globals(client_server_port) 9901 switch $argv {

        server {
                puts "opening server socket at port $globals(client_server_port)"
                socket -server Configure_Server_Client $globals(client_server_port)
                vwait forever
                }
        client {
                scan_ip 2 255
               }


Category Example