LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-04-2006, 10:58 AM   #1
techguy
LQ Newbie
 
Registered: Feb 2003
Distribution: slackware-current
Posts: 9

Rep: Reputation: 0
bash: using /dev/tcp to connect to an smtp server: issues


I'm currently working on a script that can only use bash built-ins; these are the restrictions of the target machince. I can't use netcat, mail,sendmail or any other program; I'm stuck using bash's internals.

The following works just fine.
exec 5<>/dev/tcp/google.ca/80
echo −e "GET / HTTP/1.0\n" >&5
cat <&5

However if I type this in:
exec 5<>/dev/tcp/smtp1.sympatico.ca/25
It hangs; I have to CTRL-C out of it.

I've tried doing this:
exec 5<>/dev/tcp/smtp1.sympatico.ca/25 &
And then trying to echo "EHLO" and other commands but I get nothing when I cat the file descriptor. Bash eventually returns

-bash: connect: Connection timed out
-bash: /dev/tcp/smtp1.sympatico.ca/25: Connection timed out

I've tried to dissect some example programs I found in different threads but I can't seem to find the root of my problem.

I'm currently using slackware-current, however the target box uses something very similar to slackware 8.0-8.1.

Ideas?
 
Old 09-04-2006, 11:19 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I'm currently working on a script that can only use bash built-ins; these are the restrictions of the target machince.
Cool.


Ideas?
Works for me:
Code:
exec 5<>/dev/tcp/1.2.3.4/25
cat >&5 << endofhere
EHLO domainname
HELP
QUIT
endofhere
cat <&5
 
Old 09-05-2006, 12:54 PM   #3
techguy
LQ Newbie
 
Registered: Feb 2003
Distribution: slackware-current
Posts: 9

Original Poster
Rep: Reputation: 0
I've isolated the issue to either the MTA or the network.

When I execute the command locally, I have no issues.

When I execute the same script and have it point to a remote MTA I get the initial reply from the server but I don't get anything else until the server times out.

220 smtp.perfora.net (mrelayus0) Welcome to Nemesis ESMTP server
(wait a few minutes)
421 smtp.perfora.net connection timed out

I've tried this on another MTA and it gives me the initial reply but no timeout message. Both the MTA's I tried work on different ports and I could telnet to both of them and type the commands manually through telnet.

Maybe I need to clear the send buffer after I type in the command? I'm not sure where to go from here.
 
Old 09-05-2006, 06:35 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
The script works for me to what I'd classify as run of the mill MTA's, you said you could telnet to it and issue the commands and talking to an MTA isn't rocket science. I would say it's not the script but a problem with the MTA but what I don't know.

Last edited by unSpawn; 09-05-2006 at 06:37 PM.
 
Old 09-20-2006, 11:56 AM   #5
techguy
LQ Newbie
 
Registered: Feb 2003
Distribution: slackware-current
Posts: 9

Original Poster
Rep: Reputation: 0
I just wanted to mention that after trying several MTA's that it works on certain MTA's but not on others. Two of the MTA's that didn't work were imail and "nemesis". Since it works when I need it to, I'd like to thank you for your help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect TCP Tarekaz Linux - Newbie 18 02-16-2006 02:31 PM
3C509B can not connect over TCP/IP (gets DHCP address though) RSpendl Linux - Hardware 4 10-31-2005 06:56 AM
TCP/IP configuration issues falconkid Linux - Networking 17 12-22-2004 04:10 PM
kmail - cannot connect to smtp server. emeskay Linux - Software 8 11-10-2004 10:34 PM
Can't connect to RedHat 9 SMTP server from XP bper Linux - Networking 1 10-22-2003 09:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration