0

I have hundreds of IPs in excel file like this

System name:    Server name:    Server IP   Target Port:    Environment:
AddressWash  - Crontab jobs/Scripts hostname.com     123.456.789    22  PROD

I want to take from this excel only port and IP with enviroment like and test it. Result should show me if I can reach the IP or not. Result should be in one txt file somehow formated.

Is that even possible? Thank you.

Delirium
  • 1,277
  • 3
  • 16
  • 27
  • I'm pretty sure it's possible. However, on this site you will only get help in what you do yourself. Your post looks like you are fishing for someone to do it for you, and that will earn you minus points. Watch the counter (it wasn't me). – Variatus Mar 29 '17 at 08:42
  • ah, can you recomend me page which is made for questions like this please? – Delirium Mar 29 '17 at 08:44
  • You might try elance.com – Variatus Mar 29 '17 at 08:49
  • Thank you I hope here will get some answers too. BTW: Elance seems to redirect on job searching :-) – Delirium Mar 29 '17 at 08:52

1 Answers1

0

First use this script (save it like toCSV.bat for example).It will save an excel file as csv (though the arguments needs to be full paths):

@if (@X)==(@Y) @end /* JScript comment
    @echo off


    cscript //E:JScript //nologo "%~f0" %*

    exit /b %errorlevel%

@if (@X)==(@Y) @end JScript comment */


var ARGS = WScript.Arguments;

var xlCSV = 6;

var objExcel = WScript.CreateObject("Excel.Application");
var objWorkbook = objExcel.Workbooks.Open(ARGS.Item(0));
objExcel.DisplayAlerts = false;
objExcel.Visible = false;

var objWorksheet = objWorkbook.Worksheets(ARGS.Item(1))
objWorksheet.SaveAs( ARGS.Item(2), xlCSV);

objExcel.Quit();

Then check this. And here's the final script (you can alter the result and redirect it to a file).Probably you'll have to change the name of the excel book and the sheet:

@echo off
setlocal enableDelayedExpansion
call toCsv.bat "%cd%\Book1.xlsx" Sheet1 "%cd%\csvIP.csv"

for /f "usebackq skip=1 tokens=3,4 delims=,"  %%a in ("csvIP.csv") do (
    for /f %%# in ('powershell "$t = New-Object Net.Sockets.TcpClient;try{$t.Connect("""%%~a""", %%~b)}catch{};$t.Connected"') do set "open=%%#"
    echo %%a %%b !open!
)
Community
  • 1
  • 1
npocmaka
  • 55,367
  • 18
  • 148
  • 187