Link to home
Start Free TrialLog in
Avatar of Danny Kon
Danny KonFlag for Netherlands

asked on

Find information about ports/IP/firewall settings

I like to have a script written in batch (no vb etc etc)
The batch file has to find if port 80 is open
if this is correct nothing have to be done
If this is not correct, the batch need to make a txt document if there is a internet connection and ifso it has to find out firewall settings ip settings invariement variables. So much as possible information why the connection can not be establisht.
Then if possible the text file has to be copied to somebody email and the user has to approve if this mail wil be send.
Avatar of SysExpert
SysExpert
Flag of Israel image

Not easy to do without some scripting language, access to the registry and other stuff.

I would suggest that you either loosen your restrictions, or create the code and compile it into an EXE file and run that.


I hope this helps !

Maybe some MS Resource Kit tools can help programming a command line batch file:

"portqry.exe" can query a specific port in a batch file, the result looks like this:

C:\>portqry -n %computername% -e 80

Querying target system called:

 MyComputer

Attempting to resolve name to IP address...

Name resolved to 192.168.1.10


TCP port 80 (http service): LISTENING

You can pipe this or filter this result, e.g. with the following addition:
portqry -n %computername% -e 80 | find /I "LISTENING"

(the "|" symbol is ALT 124)

In addition you could change the batch with an IF statement in order to check conditions and/or do further actions depending on the results.
Also "netsh.exe" might help to read / diag network and firewall settings, IPCONFIG /ALL >%TEMP%\%computername%.txt will pipe results into a txt file in the current users TEMP directory

I think a little batch programming knowledge is necessary to sum up all you requirements exactly
You can ask errorlevels of the commands in the next line:
ECHO %ERRORLEVEL%

"0" means normally "success", others must be checked with e.g. net helpmsg "errornumber"

Also (e.g.) "mail.exe" freeware commandline mailer tool can be found by searching the internet

So this is not a fixed solution but with the components you should be able to create your individual needed solution.

rgds
ASKER CERTIFIED SOLUTION
Avatar of usacadena
usacadena

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Danny Kon

ASKER

usacadena

Wat is that blat ??

Here is were the file is now

@echo off
::Windows script
set sys=www.sys.nl
Set stap=0
Set AdresSYS=
Set IPAdres=
Set gateway=
set XS4ALL=194.109.6.66
if exist _error.dat del _error.dat
DATE/T>_error.dat
TIME/T>>_error.dat
@echo Een ogenblik AUB de machine wordt getest

::Stap 1
::Ping het loopback adres
::Fout roept error, goed gaat door naar Stap2

for /f "tokens=2 delims==," %%a in ('ping 127.0.0.1 ^|find "4"') do if /i %%a NEQ 4 Goto :error1


::Stap 2
::Opvragen TCP/IP gegevens en ze zetten in de VAR gegevens
::(ipconfig)
for /f "tokens=2* delims=:" %%a in ('ipconfig /all ^|find /i "ip address"') do for %%b in (%%a) do set IPAdres=%%b


::Stap 3
::Ping het IPAdres
::Fout roept error, goed gaat door naar Ping remotehost
for /f "skip=5 tokens=2 delims==," %%a in ('ping %IPAdres% ^|find "4"') do if /i %%a NEQ 4 Goto :error2

:nogmaals
::Een var trukje om aan te geven dat het script maar 1 keer opnieuw mag proberenaanmaken dat bij tweede keer proberen naar een output gaat
Set /a stap+=1
If %stap% EQU 2 goto :error


::Stap 4
::Opvragen Gateway adres
for /f "tokens=2* delims=:" %%a in ('ipconfig ^|find /i "gate"') do for %%b in (%%a) do set gateway=%%b

::stap 5
::Ping Gataway
::Fout roept error, goed gaat door naar stap 6
for /f "skip=5 tokens=2 delims==," %%a in ('ping %gateway% ^|find "4"') do if /i %%a NEQ 4 Goto :error3


::stap 6
::Fout roept error anders stap 7
for /f "skip=5 tokens=2 delims==," %%a in ('ping %sys% ^|find "4"') do if /i %%a NEQ 4 Goto :error4

Echo Nog een ogenblikje AUB
::Stap 7
::Fout roept error anders einde
for /f "tokens=1* delims=:" %%a in ('tracert %XS4ALL%  -h 100 -w 10000 ^|find /i "comp"')do if /i "%%a" NEQ "Trace complete." Goto :error5
echo het programma heeft geen errors gevonden >>_error.dat &goto :eof

:error
echo deze error wordt gegenereerd als twee keer de arp gegevens zijn weggegooid >>_error.dat
goto :eof

:Error1
(echo ^<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"^>)>test.htm
(echo ^<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /^>)>>test.htm
(echo ^<html^>^<head^>)>>test.htm
(echo ^<title^>Home^</title^>)>>test.htm
(echo ^</head^>)>>test.htm
(echo ^<body^>)>>test.htm
(echo het programma geeft geen loopback adres)>>test.htm
(echo ^</body^>^</html^>)>>test.htm

goto :eof

:Error2
(echo ^<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"^>)>test.htm
(echo ^<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /^>)>>test.htm
(echo ^<html^>^<head^>)>>test.htm
(echo ^<title^>Home^</title^>)>>test.htm
(echo ^</head^>)>>test.htm
(echo ^<body^>)>>test.htm
(echo Wel loopback geen ping gegevens van het IP adres)>>test.htm
(echo ^</body^>^</html^>)>>test.htm

goto :eof

:Error3
(echo ^<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"^>)>test.htm
(echo ^<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /^>)>>test.htm
(echo ^<html^>^<head^>)>>test.htm
(echo ^<title^>Home^</title^>)>>test.htm
(echo ^</head^>)>>test.htm
(echo ^<body^>)>>test.htm
(echo wel loopback wel ping geen gataway)>>test.htm
(echo ^</body^>^</html^>)>>test.htm
goto :eof

:Error4
(echo ^<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"^>)>test.htm
(echo ^<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /^>)>>test.htm
(echo ^<html^>^<head^>)>>test.htm
(echo ^<title^>Home^</title^>)>>test.htm
(echo ^</head^>)>>test.htm
(echo ^<body^>)>>test.htm
(echo wel loopback wel ping wel gateway geen ping naar www.sys.nl)>>test.htm
(echo het programma gooit de arp gegevens weg en probeert opnieuw)>>test.htm
(echo ^</body^>^</html^>)>>test.htm

::Arp gegevens weg
netsh interface ip delete arpcache

Goto :nogmaals

:error5
(echo ^<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"^>)>test.htm
(echo ^<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /^>)>>test.htm
(echo ^<html^>^<head^>)>>test.htm
(echo ^<title^>Home^</title^>)>>test.htm
(echo ^</head^>)>>test.htm
(echo ^<body^>)>>test.htm
(echo wel loopback wel ping wel gateway wel www.sys.nl niet XS4ALL)>>test.htm
(echo ^</body^>^</html^>)>>test.htm

::verschillende mogelijkheden
::netsh interface ip set address "Local Area Connection" dhcp


start test.htm

There is some dutch insite the file but it will do the standard ip check of microsoft
My question is i want so much input as possible about errors and the solutions

Avatar of usacadena
usacadena

Yes, Blat is a Win32 command line utility that sends eMail using SMTP or post to usenet using NNTP.

http://www.blat.net/
Its not abandoned.but also not correct answered but for the rest no problem with the forced accept

Dan