Hi all and greetings.
i must admit that i have not writting dos script in many many years. that said, i am trying to write something that will kinda do the following.
i have a list of some 500+ ip address that i have saved as a .txt file. each line would look similar to
123456 84.86.160.95
or something similar.
what i want is to write a scrpit called png that takes a parameter for the name and then launches a telnet session against that. SOOO, if i typed the command line
png 123456
-- it would do
telnet 84.86.160.95
this doable?
thanks for any help you might be able to offer.
-wm
Simple .bat to loop?
Moderator: DosItHelp
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Simple .bat to loop?
This is about the easiest thing anyone's asked for on here, lol.
Change ip_addresses.txt to the path of your list.
The %%y after telnet is what places the IP address. Add any necessary switches.
Save as png.bat or png.cmd.
Usage: png name or png "name"
Change ip_addresses.txt to the path of your list.
The %%y after telnet is what places the IP address. Add any necessary switches.
Code: Select all
@echo off&echo:&setlocal enableextensions
for /f "usebackq tokens=1,2" %%x in ("ip_addresses.txt") do if "%~1"=="%%~x" telnet %%y
exit/b
Save as png.bat or png.cmd.
Usage: png name or png "name"
Re: Simple .bat to loop?
thanks for your help! one more thingy. if i wanted to include the port in the telnet statement "telnet 10000" for example, where do i include that parameter at?
Re: Simple .bat to loop?
duh, never mind. i answered my own question
thanks again for your help!
thanks again for your help!
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Simple .bat to loop?
No problem. DOS is a pain if you don't know all the features... I just painfully spent the time to learn it.
In case your solution was on the wrong track, you can either put the port numbers following the IP addresses in your file, or if it never changes, just add it to the end of the %%y, for example: %%y:80
Just don't do both, or else more programming is required, but this would allow you to have a default and custom.
In case your solution was on the wrong track, you can either put the port numbers following the IP addresses in your file, or if it never changes, just add it to the end of the %%y, for example: %%y:80
Just don't do both, or else more programming is required, but this would allow you to have a default and custom.
Re: Simple .bat to loop?
you know, that acutally solves one other problem i have! i have some 500+ modems i have connect to and 1/2 of them are on one port, the other half on another port!
if i wanted to add the port as the 3rd field in the data row, how would i need to adjust my parameters exactly?
EDIT
ok, while i am asking, i might as well ask for the whole dam thing! i am writting this script MAINLY for me, but my co-workers will also use this from time-to-time. with that in mind, i need to see if i can add a "send-key" function ONCE i am connected to the modem. is this possible to do? here is the whole picture...
telnet 10.10.10.10 10000 <enter> ; this connects me to my modem
<ctrl k>475 <enter> ; this tells the modem to show me what i need to see...this is what i want to see
i then exit out.
the problem is on the second line. an inexperienced or unknowning user could type say <ctrl j>475 and it performs an action that is unwanted! i am trying to limit their abilty to accidently screw something up....lol
what do ya think?
if i wanted to add the port as the 3rd field in the data row, how would i need to adjust my parameters exactly?
EDIT
ok, while i am asking, i might as well ask for the whole dam thing! i am writting this script MAINLY for me, but my co-workers will also use this from time-to-time. with that in mind, i need to see if i can add a "send-key" function ONCE i am connected to the modem. is this possible to do? here is the whole picture...
telnet 10.10.10.10 10000 <enter> ; this connects me to my modem
<ctrl k>475 <enter> ; this tells the modem to show me what i need to see...this is what i want to see
i then exit out.
the problem is on the second line. an inexperienced or unknowning user could type say <ctrl j>475 and it performs an action that is unwanted! i am trying to limit their abilty to accidently screw something up....lol
what do ya think?
Re: Simple .bat to loop?
ok, i figured out the first part with the 3 parameters...figured it was probably pretty simple
for /f "usebackq tokens=1,2,3" %%x in ("Stores.txt") do if "%~1"=="%%~x" telnet %%y %%z
(pushes button) "That was easy"
now that just leaves me my send-key issue...
for /f "usebackq tokens=1,2,3" %%x in ("Stores.txt") do if "%~1"=="%%~x" telnet %%y %%z
(pushes button) "That was easy"
now that just leaves me my send-key issue...
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Simple .bat to loop?
Yeah, that part is correct, but like I said, if each modem only uses 1 port, you could write the port into the IP config file so you don't have to type it every time.
You can pass a piece of text to a command's input by redirecting echo. So,
echo:475|telnet %%y %%z
Copy that line and paste it. There is a hidden command character, hex 0B before the 475 that represents CTRL+K. It looks like ♂ in Notepad/ANSI/whatever. As for enter, echo automatically sends a line return (enter) following it's output.
If that doesn't work, you're out of luck.
You can pass a piece of text to a command's input by redirecting echo. So,
echo:475|telnet %%y %%z
Copy that line and paste it. There is a hidden command character, hex 0B before the 475 that represents CTRL+K. It looks like ♂ in Notepad/ANSI/whatever. As for enter, echo automatically sends a line return (enter) following it's output.
If that doesn't work, you're out of luck.