Computing.Net > Forums > Programming > FOR loop with txt source

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

FOR loop with txt source

Reply to Message Icon

Name: AJ (by William Jimenez)
Date: November 24, 2008 at 12:31:53 Pacific
OS: Windows XP
CPU/Ram: Dell
Comment:

Hello,

how can i sue a text fiel as the source/set

Example

FOR %%a in (MyFile.txt) Do Ping %%a

Where MyFile.txt is a list of computer names in the following format:

computer1
computer2
computer3
computer4
...

This way all I have to change is MyFile.txt and let the for command do its job.

Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: Freedom
Date: November 24, 2008 at 12:52:32 Pacific
Reply:

Probably isn't the answer you were looking for, however have you looked into Windows "PowerShell" at all? It is free to use and a very valuable and powerful tool.

A person much smarter than I came up with the following powershell script. Maybe you can modify it to use it in your VB script, I'm not much for programming but I am generally resourceful enough to piggyback of someone elses work to get the same result...

Read through the directions and you will note that you only have to enter in the values for the variables that will define the network you would like to scan and the location where you would like to ouput the .txt file:

##
##Powershell script to perform a ping sweep and output responding ips to text file

#
# Variable Explanation
# w is the first octet of desired ip scan example 192.168.1.1 192 is first octet 168 is second..
# x is second octet
# y is third octet
# z is fourth octet
# upperlimit is the upper limit for the scan
# address holds the entire ip address as a string
# Lastexitcode is a native powershell variable that holds the exit code of last native command executed
# Lastexitcode = 0 is success in this case a reply recieved
# this script uses the native ping command from M$ -n is how many pings to send -w is timeout in ms
#


$w = W
$x = x
$y = y
$z = z
$upperlimit = 201
$location = "c:\PingMe.txt"
while ($y -lt $upperlimit)
{ $address = "$w.$x.$y.$z"
if ($z -eq 255)
{
++$y
$z = 0
}
$z++
$address
ping -n 1 -w 50 $address > $null
if ($Lastexitcode -eq 0)
{$address >> $location}
}

*I would like to give credit to the original author however their name has been lost through time. I'm sure this script is still readily available on the net if you want to find the original.


0

Response Number 2
Name: Mechanix2Go
Date: November 24, 2008 at 17:30:45 Pacific
Reply:

FOR /f %%a in (MyFile.txt) Do Ping %%a


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: FOR loop with txt source

cmd - for loop with ping/shutdown www.computing.net/answers/programming/cmd-for-loop-with-pingshutdown/17867.html

Exit for loop with arrays in C?! www.computing.net/answers/programming/exit-for-loop-with-arrays-in-c/8687.html

Nested for loops to seperate data www.computing.net/answers/programming/nested-for-loops-to-seperate-data/19438.html