Batch Question

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Batch Question

Post by beagle on Sun Sep 21, 2008 11:13 am
([msg=12184]see Batch Question[/msg])

I am trying to make a port scanner in batch scripting language. The only problem is, how do I get the program to show the results?
How the scanner is going to work is: I will have the user enter a host (%h%) and the port's he wants to scan. (%p%) The program will then attempt to connect using telnet to %h% using the command:
Code: Select all
telnet %h% %p%

But how do I tell the user which ports are open and closed?
What I have so far is this:
@echo off
:start
title Batch Port Scanner
color 0a
echo ***********************************
echo Enter the host you want to scan:
set /p h=
echo ************************************
goto port
:port
cls
echo *************************************
echo Enter the Ports you wish to scan on this machine:
set /p p=
echo *************************************

echo Any More? (Y/N)
set /p 0=
if %0%==n goto portscan
if %0%==y goto ports
:ports
echo Enter the ports you want to scan. The limit is 10.
set /p 1=
set /p 2=
set /p 3=
set /p 4=
set /p 5=
set /p 6=
set /p 7=
set /p 8=
set /p 9=
set /p b=
goto portscan
:portscan
cls
pause
telnet %h% %0%
telnet %h% %1%
telnet %h% %2%
011000100110010101100001011001110110110001100101
beagle
Poster
Poster
 
Posts: 244
Joined: Wed Jul 02, 2008 2:37 pm
Location: Chico, CA
Blog: View Blog (0)


Re: Batch Question

Post by vladiftodi on Sun Jan 11, 2009 8:55 am
([msg=15947]see Re: Batch Question[/msg])

I think you should switch to a different programming language
batch was never intended to be a programming language to make a port scanner...
it was more of a scripting language to automate things and make administration easier but i don't think it lives to its purpose (windows batch talking about since there is no color 0a in .nix systems you can use ANSII return codes or use a library such as ncurses... I don't know many CLI programs that even use colors (except if they implement a TUI and for a good reason...)
anyway since you are on windows AFAIK there are no pipes on windows
but I think there is input/output redirection
IF I understood what you tried to do try:
telnet %h% %p% < echo
or
telnet %h% %p% > file
to redirect the output to a file on your hdd dont forget to cd (change directory) first... it will make the file in current working directory
But again Switch to another programming language (batch isn't that powerfull and can't take you far...)
telnet is a program by itself not a function or a class... you are just redirecting its output and limited by what can telnet do...
try python it's very easy to use/learn and try it's networking library to connect to a host and port and if it fails to display something
even make a loop from port 25 to port etc...
or any other language if you prefer...
REgards
vladiftodi
New User
New User
 
Posts: 44
Joined: Thu May 22, 2008 12:29 pm
Blog: View Blog (0)


Re: Batch Question

Post by ckw100 on Sun Jan 18, 2009 11:08 am
([msg=16500]see Re: Batch Question[/msg])

See Batch files are lmited when it comes to this. The send-recive-send-recive thingfor batch files is a little to much for it.
but i would sugest to use another programing langueg. im starting to think that they on purposely limited batch files for this reason.
ckw100
New User
New User
 
Posts: 7
Joined: Sun Jan 18, 2009 10:45 am
Blog: View Blog (0)


Re: Batch Question

Post by vladiftodi on Sun Jan 18, 2009 4:26 pm
([msg=16521]see Re: Batch Question[/msg])

first of all I suggested alreayd for him to use a new programming language
and second batch was not limited on purposed it was never designed to a be an all functional language rather a scripting language to automate things...
vladiftodi
New User
New User
 
Posts: 44
Joined: Thu May 22, 2008 12:29 pm
Blog: View Blog (0)


Re: Batch Question

Post by cen on Sun Feb 22, 2009 7:09 pm
([msg=18439]see Re: Batch Question[/msg])

It's been a LONG time since I even worked on a batch file, but...

I would check to see if telnet produces an errorlevel (if memory serves, that's what it was)...

Thru that, you may be able to get a result of it crashing or not, providing a way to produce output of what's happening...
User avatar
cen
Experienced User
Experienced User
 
Posts: 77
Joined: Mon Jun 30, 2008 1:06 pm
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron