home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2005 June
/
ccd0605.iso
/
Software
/
Shareware
/
Comunicatii
/
nat32
/
mail
< prev
next >
Wrap
Text File
|
2004-03-26
|
1KB
|
76 lines
#!tcl
#
# Compute the mail server for a Domain or an IP or the Primary IP
#
# Usage: mail [ip|domain]
#
# Check args
if {$argc > 1} {
error "Usage: mail [ip|domain]
}
# Get the argument
if {$argc == 1} {
set myarg [lindex $argv 0]
} else {
set myarg [exec ip p]
}
# Is myarg a name or an address?
# If it ends with a letter, it must be a name.
set t [string match *\[a-z\] $myarg]
if {$t == 0} {
# Convert the IP to its DNS name
set response [exec ns $myarg]
set t [string first "ERROR: " $response]
if {$t != -1} {
set domain [exec setd]
if {$domain == ""} {
error "ERROR: could not resolve $myarg"
}
set host localhost.$domain
} else {
set host [lindex $response 1]
}
# Strip the hostname to get the domain name
set t [string first "." $host]
if {$t == -1} {
error "ERROR: $host invalid"
}
incr t
set domain [string range $host $t end]
} else {
set domain $myarg
}
# Get the domain's MX record
set response [exec ns -m $domain]
set t [string first "ERROR: " $response]
if {$t != -1} {
error $response
}
# Print the first MX name
set t [string first ":MX " $response]
if {$t == -1} {
error "ERROR: no MX record returned.\n$domain may be a host name, not a domain name."
}
set host [lindex $response 2]
exec set mail $host
echo $host