Solved

batch script required to check for firewall issues

Posted on 2014-11-22
13
301 Views
Last Modified: 2014-12-10
Folks

How can I build a script/batch that logs onto multiple servers and run's a telnet test for 5 different IP's?

I would like to test for firewall issues

i.e.

log onto server 1
TELNET 149.129.111.83
TELNET 149.129.111.84
TELNET 149.129.111.85
TELNET 149.129.111.86
TELNET 149.129.111.87

log onto server 2
TELNET 149.129.111.83
TELNET 149.129.111.84
TELNET 149.129.111.85
TELNET 149.129.111.86
TELNET 149.129.111.87

i would like to see the results in a log file if either successful or fail

all
0
Comment
Question by:rutgermons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
13 Comments
 
LVL 12

Expert Comment

by:andreas
ID: 40459896
#!/bin/bash


ssh user@server1 netcat -z 149.129.111.83 && echo S1 .83 telnet port OK || echo S1 .83 telnet port ERROR > out.log
ssh user@server1 netcat -z 149.129.111.84 && echo S1 .84 telnet port OK || echo S1 .84 telnet port ERROR >> out.log
ssh user@server1 netcat -z 149.129.111.85 && echo S1 .85 telnet port OK || echo S1 .85 telnet port ERROR >> out.log
ssh user@server1 netcat -z 149.129.111.86 && echo S1 .86 telnet port OK || echo S1 .86 telnet port ERROR >> out.log

ssh user@server2 netcat -z 149.129.111.83 &&  echo S2 .83 telnet port OK || echo S2 .83 telnet port ERROR >> out.log
...

Open in new window


Assumptions:

1. ssh needts to be running on server 1 and 2 and accept password less logins via kerberos or keys.
2. the tool netcat needs to be installes on both servers
0
 

Author Comment

by:rutgermons
ID: 40459902
thanks Andreas, will this work on windows servers?

is netcat included in the OS aready?
0
 
LVL 12

Expert Comment

by:andreas
ID: 40459909
nope will not run on windows. when I hear server i assume a unixoid OS, you might get it to run with installation of cygwin on all machines, but be aware that you also need to install an ssh service which also can be a security problem if it is not cared properly with. And the cygwin things wont be automatically patched over windows update.

How to realize this on windows Ive no idea.

BTW i hope the mentioned IPs are not accessible via TELNET over the internet. Its a very bad idea.

I overlooked the category the post was filed in, as its only shown very small in the EE pages...
0
Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40460161
Netcat has several Windows ports, e.g. at https://eternallybored.org/misc/netcat/, so it can be used and that is my recommendation anyway.
For starting it on remote PCs PsExec from www.sysinternals.com is a good tool. The corresponding batch file looks very similar to the suggested bash script.

Best to have the server names or IPs in a text file servers.txt. Also we will use a batch file performing the test, called testtelnet.cmd. All files should be on a network share \\server\share.
@echo off
REM testtelnet.cmd - test telnet connection to 5 fixed IP addresses
pushd %~dp0
(for /L %%i in (83,1,87) do netcat -z 149.129.111.%%i >nul && echo %computername%: %%i ok || echo %computername%: %%i failed) >> result.log
popd
exit /b

Open in new window

@echo off
REM Run tests
pushd \\server\share
psexec @servers.txt -u MyUser -p MyPassword cmd /c \\server\share\testtelnet.cmd
popd

Open in new window

Note that you need to provide credentials here, otherwise psexec will not be able to access network shares.
0
 

Author Comment

by:rutgermons
ID: 40460386
qlermo

thanks for this, i realize I missed the ports, how do I add this to this script?

cheers
0
 
LVL 12

Expert Comment

by:andreas
ID: 40460390
just add port number 23 after the IP in the netcat woild look like that:

... do netcat -z 149.129.111.%%i 23 >nul ....

rest of script remains the same. same applies to the bash script i also forgot the port numbers there.
0
 

Author Comment

by:rutgermons
ID: 40486565
andreas

I am getting an error:



PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com

\\myhostname

'netcat' is not recognized as an internal or external command,
operable program or batch file.
'netcat' is not recognized as an internal or external command,
operable program or batch file.
cmd exited on myhostname with error code 0.
Press any key to continue . . .

how exactly do I correctly call up Netcat to run the telnet?
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40486578
The script expects netcat to be on the same location as the batch file.
0
 
LVL 12

Expert Comment

by:andreas
ID: 40486588
Netcat is not a standard windows program. You need to install it first on the machines that need to use it.

You can find it here  http://www.securityfocus.com/tools/139
0
 

Author Comment

by:rutgermons
ID: 40492619
I've requested that this question be closed as follows:

Accepted answer: 0 points for rutgermons's comment #a40460386

for the following reason:

good
0
 
LVL 12

Expert Comment

by:andreas
ID: 40492620
you should distribute the points when closing the topic to the participants according to the usefulness regarding solving your problem.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40492634
I'm objecting,  as you selected your own comment as answer. Please make sure to use the action buttons above the comment to accept.
0
 

Author Closing Comment

by:rutgermons
ID: 40492642
good
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question