Script for checking firewall connection

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for checking firewall connection
# 1  
Old 08-11-2011
Script for checking firewall connection

Dear all

I am writing a shell script to use telnet for the connection test

There are 3 cases to test and detail as:

/* Case 1 - The port can be connected */
# telnet host_a 20101 < /dev/null 2>&1 | grep -q Connected
# echo $? return 0

/* Case 2 - The port cannot be connected */
# telnet host_a 20102 < /dev/null 2>&1 | grep -q Connected
# echo $? return 1

/* Case 3 - The port is blocked by Firewall */
# telnet host_b 21701 < /dev/null 2>&1
# Need to use Ctrl+C to exit

For case 1 and case 2, I am able to handle in a script. However, I don't know how to handle case 3 in script, it is hold when "Trying 160.1.1..." and need to use Ctrl+C to exit.

Please advise me on case 3. Thanks in advance.


Last edited by pludi; 08-11-2011 at 07:12 AM..
# 2  
Old 08-15-2011
echo "host_b 21701" |xargs telnet

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

AIX firewall accept established connection

I'm trying to configure a firewall for AIX to accept incoming connections on ports 22 and 443 and deny everything else. All is ok; the server accepts connections only on 22 and 443, but after that I also need to accept all outgoing connections -- ssh and telnet, for example. So I started with ... (0 Replies)
Discussion started by: Michael1457
0 Replies

2. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "" | grep -v grep) #check is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r / 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

3. UNIX for Dummies Questions & Answers

I have firewall rules to open ports, why telnet refuses connection?

Alright... this question comes from the fact that I'm trying to setup postfix to relay messages to Office 365 SMTP but its giving me connection refused... I read that if you have doubts if your port is open or not you should telnet to them so thats what I did. This is a Red Hat 6.3 box. My... (4 Replies)
Discussion started by: RedSpyder
4 Replies

4. Solaris

Solaris 10 ftp connection problem (connection refused, connection timed out)

Hi everyone, I am hoping anyone of you could help me in this weird problem we have in 1 of our Solaris 10 servers. Lately, we have been having some ftp problems in this server. Though it can ping any server within the network, it seems that it can only ftp to a select few. For most servers, the... (4 Replies)
Discussion started by: labdakos
4 Replies

5. Debian

not run script firewall (lenny 5.0.4)

startup script displays a message: # /etc/init.d/firewall start Starting firewall: iptables iptables v1.4.2: Can't use -i with OUTPUT Try `iptables -h' or 'iptables --help' for more information. iptables v1.4.2: Can't use -i with OUTPUT not to understand what is wrong in the... (2 Replies)
Discussion started by: moskovets
2 Replies

6. Shell Programming and Scripting

Firewall Check Script

Hello, I made a following script that check every 5 minutes to check firewall is running or not, if firewall down that raise an alert only once, but following script generate an alert every 5 minutes according to cronjob: FILE="/var/log/fwstatus" CHK="/tmp/fwstatus" service... (1 Reply)
Discussion started by: telnor
1 Replies

7. IP Networking

checking a connection still exists?

Hi I have a bit of c code which I'm trying to use as a relay between apache and a scgi cluster. Example of problem code is below: while((n = recv(scgiSock, local_data, MAX_LENGTH, 0)) > 0) { time(&t2); time_now = t2 - t1; if(time_now > TIMEOUT) ... (2 Replies)
Discussion started by: fishman2001
2 Replies

8. Shell Programming and Scripting

checking a connection

Hello, Is it possible to check if a host is accepting connections on a particular port using a shell script? Can't we automate telnet to check for the same? Thanks in advance Azmath H Shaik (3 Replies)
Discussion started by: azmathshaikh
3 Replies

9. Cybersecurity

The Best Script For Iptables Firewall

UTIN Firewall script for Linux 2.4.x and iptables ============================================== #!/bin/sh # # rc.firewall - UTIN Firewall script for Linux 2.4.x and iptables # # Copyright (C) 2001 Oskar Andreasson <bluefluxATkoffeinDOTnet> # # This program is free software; you can... (5 Replies)
Discussion started by: binhnx2000
5 Replies
Login or Register to Ask a Question