Showing posts with label cmd. Show all posts
Showing posts with label cmd. Show all posts

Monday, January 5, 2009

My Experiments with CMD - The FOR Command


I am really an admirer of "FOR" command.
 
The possibilities with For command are end less :-)

To generate a simple ping sweeper
 
Imagine you have to monitor 10 systems for its availability through "ping" command.

Say the systems are in the IP range 10.0.0.1 to 10.0.0.10

C:\> For %i in (1,2,3,4,5,6,7,8,9,10) do ping 10.0.0.%i

It starts pinging the IPs one by one. :-)
 
 Ping sweeper Version II
Now lets change the way we define the set..

C:\> For /L %i in (1,1,10) do ping 10.0.0.%i

Lets analyze (1,1,10) a bit more. Its (start,Step,end). So play it around further !!!

To ping from 10 to 1 it would be

C:\> For /L %i in (10,-1,1) do ping 10.0.0.%i
 
 
 Ping sweeper Version III

Lets play around with the way we defined "set" further.

Lets create a text file containing the following text and name it as list.txt.

10.0.0.1 ;
10.0.0.2 ;
10.0.0.3 ;
10.0.0.4 ;
10.0.0.5 ;
10.0.0.6 ;
10.0.0.7 ;
10.0.0.8 ;
10.0.0.9 ;
10.0.0.10 ;
 
              Now try this.

C:\> For /F "eol=;" %i in (list.txt) do ping %i

It is still a ping sweeper and now the list of systems to be sweeped is taken from the text file speficied.
 

My Experiments with CMD - The windows Console Shell


It is easy to invoke a cmd shell from windows.  Click Start -> Run and  type in "cmd"

Initiating CMD
  • The cmd shell can be considered an old MS DOS System.
If you say, hey I know this and every one else know this, I would say yes.. we all know this.. Now lets explore the cmd shell in forth coming posts :-)

"My Experiments With" Series


Thought of capturing my experiences in various domains like Windows Internals, Scriping, Security and more..

Watch out :-)