LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-23-2018, 08:20 PM   #1
chiguy1256
LQ Newbie
 
Registered: Feb 2018
Posts: 4

Rep: Reputation: Disabled
Telnet Script or Equivalent


I need a shell script that either reads input from a file that contains IP addresses and TCP ports or this information can be contained in the script itself. I need to telnet to the addresses and write the results to a log. This will be used to maintain ACL/firewall connectivity. Please advise. Thanks.
 
Old 02-24-2018, 12:18 AM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
what have you done so far ?
and please show your work

- guessing this might be homework ?

also tellnet should NOT be used !!!
- yes there are exceptions but it is very INSECURE
 
1 members found this post helpful.
Old 02-24-2018, 12:18 AM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
what have you done so far ?
and please show your work

- guessing this might be homework ?

also tellnet should NOT be used !!!
- yes there are exceptions but it is very INSECURE
 
1 members found this post helpful.
Old 02-24-2018, 12:52 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729
Yes, please show your work so far.

Avoid telnet. If you are just getting started look at an SSH or SFTP client instead. They are secure and they are easier to script. If you've already done some work trying to use telnet, stop, erase it, and look at an SSH or SFTP client instead.
 
Old 02-24-2018, 09:24 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,693

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by chiguy1256 View Post
I need a shell script that either reads input from a file that contains IP addresses and TCP ports or this information can be contained in the script itself. I need to telnet to the addresses and write the results to a log. This will be used to maintain ACL/firewall connectivity. Please advise. Thanks.
Read the "Question Guidelines" link in my posting signature. As others have said, we're happy to help, but you have to show your own efforts first. We aren't going to write your scripts for you, and you can find MANY examples of bash telnet scripts with the same internet search you used to find this site.
 
Old 02-25-2018, 08:24 AM   #6
chiguy1256
LQ Newbie
 
Registered: Feb 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
John VV

Quote:
Originally Posted by John VV View Post
what have you done so far ?
and please show your work

- guessing this might be homework ?

also tellnet should NOT be used !!!
- yes there are exceptions but it is very INSECURE

John VV, no this is not homework. Doing some work for my employer. There is an IBM application that I support on some Red Hat Linux and IBM AIX servers we have. However, I don't work on these environments very much and do not have much scripting experience. I do know that on both systems I do not have access to nmap or netcat.

Below is a sample script I found online. This uses /dev/tcp. It works fine, but displays results to the screen. I want to log the information/results.

I am going to ask some of my UNIX/Linux counterparts at work as well.

Whatever method is used, I just need to insure that it satisfies the firewall.

Thank you in advance.

#!/bin/bash
echo "scanme.nmap.org 80
scanme.nmap.org 81
192.168.0.100 1" | (
TCP_TIMEOUT=3
while read host port; do
(CURPID=$BASHPID;
(sleep $TCP_TIMEOUT;kill $CURPID) &
exec 3<> /dev/tcp/$host/$port
) 2>/dev/null
case $? in
0)
echo $host $port is open;;
1)
echo $host $port is closed;;
143) # killed by SIGTERM
echo $host $port timeouted;;
esac
done
) 2>/dev/null # avoid bash message "Terminated ..."
 
Old 02-25-2018, 09:19 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,693

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by chiguy1256 View Post
John VV, no this is not homework. Doing some work for my employer.
Ah...so since you're asking US to do your work then, how much of your paycheck do we get for doing it?
Quote:
There is an IBM application that I support on some Red Hat Linux and IBM AIX servers we have. However, I don't work on these environments very much and do not have much scripting experience. I do know that on both systems I do not have access to nmap or netcat.
This is very confusing; you say that your job is supporting an application on RHEL and AIX servers...then say you don't work on these environments very much?? How, exactly, do you support them then? And there are THOUSANDS of bash scripting tutorials you can find online to get you started. And since this is for your job, wouldn't it be a good idea if you learned to to it?

You also don't say what this 'application' is that you support. There may be other ways of doing things.
Quote:
Below is a sample script I found online. This uses /dev/tcp. It works fine, but displays results to the screen. I want to log the information/results. I am going to ask some of my UNIX/Linux counterparts at work as well. Whatever method is used, I just need to insure that it satisfies the firewall.
If you're wanting to satisfy the security requirements...you DO NOT want to use telnet. At all; ever. It is horribly insecure, and has been for decades now. Since your company is paying for RHEL and AIX (and AIX isn't cheap), your company must be large enough to take security seriously. Why do you not use SSH, and do a keyswap, making whatever you have to do MUCH easier?
Quote:
Code:
#!/bin/bash
echo "scanme.nmap.org 80
scanme.nmap.org 81
192.168.0.100 1" | (
  TCP_TIMEOUT=3
  while read host port; do
    (CURPID=$BASHPID;
    (sleep $TCP_TIMEOUT;kill $CURPID) &
    exec 3<> /dev/tcp/$host/$port
    ) 2>/dev/null
    case $? in
    0)
      echo $host $port is open;;
    1)
      echo $host $port is closed;;
    143) # killed by SIGTERM
       echo $host $port timeouted;;
     esac
  done
  ) 2>/dev/null # avoid bash message "Terminated ..."
So run the script "<script name> > /some/output/file.txt"
There you go. Script output to a file name. And using /dev/tcp isn't a good idea. If it's not your job to work with unix/Linux servers, then why aren't the unix/Linux support folks doing the scripting for their systems?
 
Old 02-25-2018, 09:36 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,945

Rep: Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325
I can't see how is this script related to "maintain ACL/firewall connectivity". By the way, what do you mean by that at all?
 
1 members found this post helpful.
Old 02-25-2018, 01:34 PM   #9
chiguy1256
LQ Newbie
 
Registered: Feb 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Ah...so since you're asking US to do your work then, how much of your paycheck do we get for doing it?

This is very confusing; you say that your job is supporting an application on RHEL and AIX servers...then say you don't work on these environments very much?? How, exactly, do you support them then? And there are THOUSANDS of bash scripting tutorials you can find online to get you started. And since this is for your job, wouldn't it be a good idea if you learned to to it?

You also don't say what this 'application' is that you support. There may be other ways of doing things.

If you're wanting to satisfy the security requirements...you DO NOT want to use telnet. At all; ever. It is horribly insecure, and has been for decades now. Since your company is paying for RHEL and AIX (and AIX isn't cheap), your company must be large enough to take security seriously. Why do you not use SSH, and do a keyswap, making whatever you have to do MUCH easier?

So run the script "<script name> > /some/output/file.txt"
There you go. Script output to a file name. And using /dev/tcp isn't a good idea. If it's not your job to work with unix/Linux servers, then why aren't the unix/Linux support folks doing the scripting for their systems?

I apologize for the post. Admins, if you want, you can go ahead and delete the entire thread.
 
Old 02-25-2018, 02:23 PM   #10
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,693

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by chiguy1256 View Post
I apologize for the post. Admins, if you want, you can go ahead and delete the entire thread.
No one is saying to delete it, but you have to SHOW YOUR OWN EFFORTS here. You found a script, and you say it does what you need...and you were told to run that script followed by the ">" to redirect output to a file, which is what you asked for.

You were ALSO given advice to not use telnet, but to use SSH. You won't name the application (so we cannot offer ideas on alternative to what you're doing), explain what you mean by "maintain ACL/firewall connectivity", tell us how you administer this application on AIX/Linux without actually getting ON those systems, or how you expect to deploy these things if you're not on the Linux/Unix admin team (which, it seems, you're not).

We're happy to help you, but if you won't answer questions or take advice, there isn't much use in posting. Telnet is insecure; do not use it. Use ssh, keyswap, and you can run commands remotely through a VERY simple script. And still be secure.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] What is the equivalent of this bash script in sh script? archieval Programming 3 10-05-2010 03:09 AM
telnet -> use contrl-D to exit using python telnet script athreyavc Programming 5 07-06-2009 11:17 PM
telnet equivalent on linux somsahi Linux - Hardware 3 09-09-2006 03:11 PM
Running Telnet in a script, want to save Telnet output, howtodothis??? anil3 Linux - Software 2 03-08-2006 04:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:37 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