Solved

help needed w Windows batch script

Posted on 2016-07-16
10
44 Views
Last Modified: 2016-07-18
I have in mind to write the following Windows batch script to poll entire range of 254 IP subnet to see
if the IP has web server listening on it;  help me fix the codes below to get it working:

echo off
do while reading c:\temp\wgetoutput.txt
wget -S <IP_from_IPlist.txt>  2> c:\temp\wgetoutput.txt
if %errorlevel% == 0 then find "Server:" >> c:\temp\websvrtype.txt
  else
echo "not a webserver" >> >> c:\temp\websvrtype.txt
endif



I have the wget tool & it's tested working.
The error output  (ie 2> )  of  'wget -S IP_addr' is as below:

If successfully connected to a web server: (ie errorlevel is 0)
=================================
Connecting to 10.1.10.71:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.0 301 Redirect
  Server: GoAhead-Webs
  Date: Fri Jan 14 18:41:53 2106
  Pragma: no-cache
  Cache-Control: no-cache
  Content-Type: text/html
  Location: index.asp

If unsuccessfully connected to a web server: (errorlevel is usually 1 but can be high value if IP invalid; so all non-zero values)
====================================
           => `index.html.1'
Connecting to 10.1.10.1:80... failed: Connection refused.
0
Comment
Question by:sunhux
[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
  • 3
  • 2
  • 2
  • +2
10 Comments
 

Author Comment

by:sunhux
ID: 41714741
correction:

if %errorlevel% == 0 then find "Server:" >> c:\temp\websvrtype.txt
    should read
if %errorlevel% == 0 then find "Server:" c:\temp\wgetoutput.txt >> c:\temp\websvrtype.txt
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 70 total points
ID: 41714751
You might consider one of the programs that already exist like AngyIP scanner.  http://angryip.org/
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41714754
Here http://www.advanced-ip-scanner.com/ is another that doesn't require JAVA.
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 54

Assisted Solution

by:Joe Winograd, EE MVE
Joe Winograd, EE MVE earned 100 total points
ID: 41714771
Hi sunhux,
I can't help you with that batch file, but along the lines of Dave's posts, this EE article provides a solution that may interest you:
Test IP Addresses with PING

Regards, Joe
0
 
LVL 95

Assisted Solution

by:John Hurst
John Hurst earned 50 total points
ID: 41714776
I also use Advanced IP Scanner. It works well, does what you want and can save the results to a file.
0
 
LVL 54

Assisted Solution

by:Joe Winograd, EE MVE
Joe Winograd, EE MVE earned 100 total points
ID: 41714782
sunhux,
One other thing. If you don't want to install AutoHotkey and prefer to download an executable (an EXE file), such as with the two links that Dave provided, then I'll be happy to compile it for you into a stand-alone executable (an EXE file that requires no installation — just run it), as mentioned in my PING article. Regards, Joe
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 280 total points
ID: 41715706
As you seem to get a list of web server types, too, none of the tools suggested will help you IMHO. I've hardcoded the IP subnet 192.168.0.0 below. The script will go thru all 254 addresses. Also, your suggested output does not show the IP address, which makes the resulting file rather useless - I've added that part, too.
@echo off
setlocal EnableDelayedExpansion
set net=192.168.0
del c:\temp\websvrtype.txt 2>nul
for /L %%A in (1,1,254) do (
  set srv=%net%.%%A
  set type=
  for /F "tokens=1* delims=: " %%R in ('wget -S %net%.%%A  2^>^&1 ^| find "Server:"') do set type=%%S
  if "!type!" == "" (
    echo !srv!: not a web server 
  ) else (
    echo !srv!: !type!
  )
) >> c:\temp\websvrtype.txt

Open in new window

0
 

Author Comment

by:sunhux
ID: 41715755
excellent, I'll test it out tomorrow
0
 

Author Comment

by:sunhux
ID: 41717038
I just made one minor change so that it doesn't take very long when wget polls
IP addresses that are not in use or not responding :

('c:\wget\wget -S -t 1 --timeout=2 %net%.%%A  2^>^&1 ^| find "Server:"')

ie
-t 1 : number of tries is 1
--timeout=2 : timeout after 2 secs

& it worked marvelously without triggering IPS/IDS/firewall events in our Arcsight
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 41717069
Good move to lessen the timeout and retries. Also, with this (non)speed it doesn't surprise me no IDS is complaining - it is just too slow to do so. Anyway, usually the target IDS is the one checking for attacks, not your local one.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
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…

751 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