home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2005 June
/
ccd0605.iso
/
Software
/
Shareware
/
Comunicatii
/
nat32
/
identd.tcl
< prev
next >
Wrap
Text File
|
2001-10-12
|
2KB
|
99 lines
#!tcl
#
# IDENTD Forwarder
#
set port 113
# Listen at Port for connection requests
set s [socket -p $port 1]
while {1} {
# accept an incoming request
set ns [$s accept]
# where did it come from
set sip [$ns getaddr]
# got one, now read it
set data [$ns gets 512]
# echo IDENTD: got $data from $sip
# parse the request
set lport [lindex $data 0]
set lport [string trim $lport ,]
set fport [lindex $data 1]
# fetch the Port Map from NAT32
set pmap [exec "pmap"]
# parse the pmap
set addr "not found"
set pmap [split $pmap "\n"]
foreach v $pmap {
set ipsrc [lindex $v 1]
set ipdst [lindex $v 2]
set prot [lindex $v 3]
set dp [lindex $v 4]
set sp [lindex $v 5]
set nsp [lindex $v 6]
if {$ipdst == $sip && $prot == "6" && $lport == $dp && $fport == $nsp} {
set addr $ipsrc
break
}
}
if {$addr == "not found"} {
$ns puts "$lport, $fport : USERID : UNIX : NAT32\n"
$ns shutdown
rename $ns {}
continue
}
# open a socket to the private machine
set cs [socket $addr $port]
if {[lindex $cs 0] == "can't"} {
$ns shutdown
rename $ns {}
continue
}
# send the request to that machine
$cs puts $data
# read the response
set data [$cs gets 512]
# close the socket
rename $cs {}
# return the response to the orginal server
$ns puts $data
# close the socket in the send direction
$ns shutdown
#close the socket and loop for the next request
rename $ns {}
}