# ipconfig.bat



## G-Stress

Hey guys, new to the forums and new to batch scripting. I'm trying to create a little network testing script. I got everything working, however in the "ping" section I am having hard time trying to figure out how I can set it up so it will prompt for a host to ping then ping the host.

I imagine tracert will need to same thing ping will I just can't figure out hot exactly to set it it up that way.

Thanks in advance for any help/advice.



Code:


@echo off
:options
cls
echo =====================
echo MENU OPTIONS:
echo =====================
echo   ipconfig
echo   ipconfig all
echo   release
echo   renew
echo   flushdns
echo   reset winsock
echo   ping
echo   tracert
echo =====================
echo   q to quit
echo =====================
set /p input="Enter Options Here: "

if "%input%"=="ipconfig" goto:ipconfig
if "%input%"=="ipconfig all" goto:ipconfigall
if "%input%"=="release" goto:release
if "%input%"=="renew" goto:renew
if "%input%"=="flushdns" goto:flushdns
if "%input%"=="reset winsock" goto:winsock
if "%input%"=="ping" goto:ping
if "%input%"=="tracert" goto:tracert
if "%input%"=="q" goto:exit

echo Please choose from the Options listed above!
pause
goto:options

:ipconfig
ipconfig.exe
pause
goto:options


:ipconfigall
ipconfig.exe /all
pause
goto:options

:release
ipconfig.exe /release
pause
goto:options

:renew
ipconfig.exe /renew
pause
goto:options


:flushdns
ipconfig.exe /flushdns
pause
goto:options


:winsock
netsh winsock reset
pause
goto:options


:ping
ping yahoo.com
pause
goto:options


:tracert
tracert yahoo.com
pause
goto:options


:exit
exit


----------



## TheOutcaste

Just use another set /p line:



Code:


:ping
set /p host="Enter Host to ping: "
ping "%host%"
pause
goto options

You can do the same for tracert

Also, the ":" is not needed on the goto lines as I've shown above.
The current script is case sensitive, so if they type Ping instead of ping or if they mistype something it loops, not exactly user friendly. You can add the /I switch to the If command so it is not case sensitive, or you may want to consider using a numbers list. Adding numbers let's the user just enter the number of the item rather than typing the entire name
Try:



Code:


echo =====================
echo MENU OPTIONS:
echo =====================
echo 1  ipconfig
echo 2  ipconfig all
echo 3  release
echo 4  renew
echo 5  flushdns
echo 6  reset winsock
echo 7  ping
echo 8  tracert
echo =====================
echo   q to quit
echo =====================
set /p input="Enter Options Here: "

if "%input%"=="1" goto ipconfig
if "%input%"=="2" goto ipconfigall
if "%input%"=="3" goto release
if "%input%"=="4" goto renew
if "%input%"=="5" goto flushdns
if "%input%"=="6" goto winsock
if "%input%"=="7" goto ping
if "%input%"=="8" goto tracert
if /I "%input%"=="q" goto exit

You can also use *if /I "%input:~0,1%"=="q" goto exit* This only checks for the 1st letter typed to be q or Q, so they can type q or quit, or qwerty and it will exit.

HTH

Jerry


----------



## G-Stress

@ TheOutcaste,

Thank you so much man I'm new to the whole batch scripting and I figured I'd try and create small scripts of simple tasks to familiarize myself and how things work.

I tried for awhile i knew it had to be something soooo simple I tried



Code:


set /p input="%address%"
echo "Enter host to ping: "
ping %address%

but that didn't work, not looking at your code I see I just didn't define the variable properly. Thanks again. I'm not sure if karma is available here, but if so +1


----------



## G-Stress

Forgot to add, case sensitive being mentioned and the code you specified if I wanted to use it for words for example "ping" would it be



Code:


if /I "%input:~ping,Ping%"=="ping" goto :ping

or would it still be 0,1? Oh and I thought about using the numbered system like you mentioned also, but I like typing the commands, I may end up using it though


----------



## TheOutcaste

The *slash I* makes the compare non-case sensitive, so to use the words,just add the */I* to your original script:


Code:


if /I "%input%"=="ping" goto ping

This will match ping, Ping, PiNg, PIng, etc

The ~0,1 structure I showed in *if /I "%input:~0,1%"=="q" goto exit* is to extract just the 1st letter. ~0 means start at offset 0 (beginning of line, no offset) and grab a string of length 1. With the /I that means to quit you can type q, Q, quiet, or quonset, and all will exit, just as long as the first letter is q or Q.

You could use this if you wanted to be able to type just the first few letters rather than the whole name, but not have it fail if you did type the entire command:


Code:


echo =====================
echo MENU OPTIONS:
echo =====================
echo   ipconfig
echo   ipconfig all
echo   release
echo   renew
echo   flushdns
echo   reset winsock
echo   ping
echo   tracert
echo =====================
echo   q to quit
echo =====================
set /p input="Enter Options Here: "

If /I "%input%"=="ipconfig" goto ipconfig
If /I "%input%"=="ipconfig all" goto ipconfigall
If /I "%input:~0,3%"=="rel" goto release
If /I "%input:~0,3%"=="ren" goto renew
If /I "%input:~0,3%"=="flu" goto flushdns
If /I "%input:~0,3%"=="res" goto winsock
If /I "%input:~0,3%"=="pin" goto ping
If /I "%input:~0,3%"=="tra" goto tracert
if /I "%input:~0,1%"=="q" goto exit

With this, you only need to type the first three letters, but can type the entire word; only the 1st three letters need to match, so "flu shot" is the same as "flushdns".
Since ipconfig and ipconfig all are the same for the first 8 characters, you can't use just the first 3 letters for both. If you check for *all* _first_ though, you can use *ipc* for ipconfig. This can be done with environment variable substitution: 


Code:


set /p input="Enter Options Here: "

If /I "%input:*all=ipall%"=="ipall" goto ipconfigall
If /I "%input:~0,3%"=="ipc" goto ipconfig
If /I "%input:~0,3%"=="rel" goto release

with this, if the user types anything that ends with *all*, ipconfig all is executed. "fall", "release all" "Bounce the basketball" will all do ipconfig all, and ipconfig can be done with just *ipc*. Note that this does NOT change the contents of input, it only changes what is used in the if comparison. So another option is:


Code:


set /p input="Enter Options Here: "
set input=%input:*all=ipa%

If /I "%input:~0,3%"=="ipc" goto ipconfig
If /I "%input:~0,3%"=="ipa" goto ipconfigall

If the user types anything that ends with *all*, input is changed to *ipa*. If input doesn't end with *all*, input is not changed, as the statement becomes in effect *set input=%input%*
With this, you can type *ipa*, *all*, *fall*, *ipconall*, or* ipconfig all* to run ipconfig all, and type *ipc* for ipconfig.

HTH

Jerry


----------



## G-Stress

Ahhh... interesting. I think I will keep it case sensitive, but I will definitely mess around with that also. I take it "0,3" just means the first 3 letters?

I'm trying to think of some more little networking commands to add. I've learned alot just from your posts, your very detailed in a user friendly way

Thanks again.


----------



## TheOutcaste

G-Stress said:


> Ahhh... interesting. I think I will keep it case sensitive, but I will definitely mess around with that also. I take it "0,3" just means the first 3 letters?...


Yup. For fun and counting skills test, you can use ~3,3, which is the 4th, 5th, and 6th letters



G-Stress said:


> ...I'm trying to think of some more little networking commands to add. I've learned alot just from your posts, your very detailed in a user friendly way
> 
> Thanks again.


arp, getmac, hostname, nbtstat, net, netsh, netstat, nslookup, pathping, and route are a few useful ones.
Less useful are mrinfo (only useful if you have a multicast router), rcp, rexec, and rsh.
systeminfo, while not really a "network" command, does provide network info as part of it's output.
Some commands won't recognize /? for help so use -? instead, others have no builtin help, so you can search the net for usage tips and tricks.

HTH

Jerry


----------



## G-Stress

You are the man so basically ~3,3 starts on the 4th. then the second 3 is how many characters it "reads" i guess? so if it were ~2,4 it would start on character 3 and do 3,4,5,6?

I got it but what exactly is "~" what does that mean I haven't been able to find any good info on it or the | command. I been doin alot of research and reading here:

not sure if I can post links so I'll space it.

http technet. microsoft. com/en-us/library/bb491071.aspx

I just read about the rexec and have not been able to get it working yet. I read it needed to have the service daemon running on the machine, but I didn't see anywhere in the services or nuttin on my computer to start/stop it at all. Althought I didn't research it alot just messed with it for a minute.

Thanks for all the added options now I'm gonna try and add them


----------



## TheOutcaste

You got it:up:

The "~" is called a tilde, why it was picked I haven't a clue, but some info can be found here under Punctuation and also Computing here: http://en.wikipedia.org/wiki/Tilde
The "|" is the pipe command and is used to send the output of one command as input to another
http://dos.rsvs.net/DOSPAGE/BATCHCOM.HTM#3
http://support.microsoft.com/kb/46376

Using two pipe symbols (||) is the opposite of using two ampersands (&&):
&& between two commands will run the second command only if the first is successful
|| between two commands will run the second command only if the first fails

Copy file1.txt file2.txt && echo Copy successful >>log.txt
*Copy successful *will be written to the file log.txt only if the copy succeeds

rd junkfldr || echo Directory junkfldr was not removed>>errors.txt
*Directory junkfldr was not removed* will be written to the file errors.txt only if it fails

You can post links, just paste/type them in.

[WEBQUOTE="http://technet.microsoft.com/en-us/library/bb490989.aspx"]Windows XP and Windows 2000 do not provide the Rexec service[/WEBQUOTE]
The Rexec service is a Unix service, so unless you are connected to a Unix server, rexec is not very useful.

I've found this site http://www.allenware.com/icsw/icswidx.htm to be useful for learning DOS commands. While written for Win9x/ME, it still pretty useful.


----------



## G-Stress

Once again thanks alot man  You basically just made me a programmer  I'm gonna work on adding the other features tonight and will post what I add and how i add it. Come to think of it I have heard of the "tilde" before, but forgot until now. I will check out those links also.

Time to have some good 'ol batch fun now 

Thanks


----------



## G-Stress

Okay, I added a few so far and to be able to use the switches/arguments with the commands I set them up like the ping command



Code:


:netsh
set /p nets="Please Specify Argument: "
netsh "%nets%"
pause
goto options

would that be the best way to use them with the arguments? that way I would type

>netsh
Please Specify Argument: firewall set opmode enable

hmmm... yea this works, but I have to know exactly what I want or it goes to pause it won't continue the command until im done with it... hmmmm... this might come in handy now to add the "done" or "quit" option instead of going to pause on some of these...

or actually I can take out the (set /p="Please Specify Argument: ") and maybe set an input to after the netsh if input=done goto options.


----------



## G-Stress

nevermind all i need really is



Code:


:netsh
netsh 
goto options

and then just add a

REM exit to quit command

or something like that


----------



## TheOutcaste

Since your 1st line is Echo off, you'll need to echo the info to the screen, as a REM line will not be seen. I'd use something like:


Code:


Echo Starting NETSH shell interface. Type 'Help' for a list of Commands
Echo Type EXIT to return to this Menu

Jerry


----------



## G-Stress

Yea I realized that after I tried it

Thanks though


----------



## G-Stress

Hey bud, another addition I think I'm gonna add is a router login function set to open up to most common default router logins. Now I got it figured out, what I did was just copy a firefox directory to the same folder of the .bat file and have it run for say a linksys

:linksys
echo "default username is "blank" password is "admin"
pause
firefox.exe -new-window http://192.168.1.1
goto options

it works fine. What im wondering, because of this method I would need to zip or compile all of the files to one file then of course they would have to be extracted before use. Is there a way to either compile all files into one and run without extraction or an easier way without needing a directory so I can use all functions with one script file?

I guess I can think of maybe and

If exist %program files%\internet explorer\iexplore.exe
iexplore.exe whatever command line options are used for ie http://routerlogin

hmmm....


----------



## TheOutcaste

try


Code:


[B]start [url]http://192.168.1.1[/url][/B]

That should open that address in the default browser, either IE, Firefox, Opera, etc. No need to copy the firefox folder


----------



## G-Stress

ahhh... I feel so dumb now... thanks man


----------



## G-Stress

Hey bud, wondering if you might have a tip or to. I'm trying to get msconfig and device manager added.

I got msconfig working, but for some reason device manager will not work. It does however run directly from the command line which I don't understand the difference being that my cmd opens at:

C:\Documents and Settings\username>



Code:


:msconfig
%windir%\pchealth\helpctr\binaries\msconfig
goto options

:device
%windir%\system32\devmgmt.msc
goto options


----------



## TheOutcaste

Hmm, works ok for me from both the command line and in a batch file. Without seeing the entire file my first guess would be something not working right with the input/goto line. Double check that for typos. You might try commenting out the *echo off* line, then you can see each step of the process. That can often help to pin down the problem.

If you want to attach/post the current version of your file I can give it a try and see if I get the same result.

Jerry


----------



## G-Stress

You were right man  it was the "%input%" at the end of it I had ' instead of ". I don't know how I missed that. Oh and thanks for the echo on tip I forgot about that. I was inserting "pause" to hopefully try to troubleshoot, but in that case it still just closed the cmd prompt.

Here is what I've added so far:



Code:


@echo off
:options
cls
echo IPCONFIG v1.0 By G-Stress
echo.
echo =====================
echo IP MENU OPTIONS:
echo =====================
echo   ipconfig
echo   ipconfig all
echo   release
echo   renew
echo   flushdns
echo   reset winsock
echo   ping
echo   ping -t (continious ping ctrl+c to stop)
echo   tracert
echo   getmac
echo   arp
echo   hostname
echo   nbtstat
echo   net
echo   netsh
echo   nslookup
echo   pathping
echo   router login
echo   windows version
echo   msconfig
echo   device manager
echo =====================
echo   q to quit
echo =====================
set /p input="Enter Options Here: "
echo.
echo.
echo.

if "%input%"=="ipconfig" 	goto:ipconfig
if "%input%"=="ipconfig all" 	goto:ipconfigall
if "%input%"=="release" 	goto:release
if "%input%"=="renew" 		goto:renew
if "%input%"=="flushdns" 	goto:flushdns
if "%input%"=="reset winsock" 	goto:winsock
if "%input%"=="ping" 		goto:ping
if "%input%"=="ping -t" 	goto:pingt
if "%input%"=="tracert" 	goto:tracert
if "%input%"=="getmac" 		goto:getmac
if "%input%"=="arp" 		goto:arp
if "%input%"=="hostname" 	goto:hostname
if "%input%"=="nbtstat" 	goto:nbtstat
if "%input%"=="net"		goto:net
if "%input%"=="netsh"		goto:netsh
if "%input%"=="netstat"		goto:netstat
if "%input%"=="nslookup"	goto:nslookup
if "%input%"=="pathping"	goto:pathping
if "%input%"=="router login"	goto:router
if "%input%"=="windows version"	goto:version
if "%input%"=="msconfig"	goto:msconfig
if "%input%"=="device manager"	goto:devicem
if "%input%"=="q" 		goto:exit
echo Please choose from the Options listed above!
echo.
echo.
pause
goto:options



:ipconfig
ipconfig.exe
pause
goto:options



:ipconfigall
ipconfig.exe /all
pause
goto:options



:release
ipconfig.exe /release
pause
goto:options



:renew
ipconfig.exe /renew
pause
goto:options



:flushdns
ipconfig.exe /flushdns
pause
goto:options



:winsock
netsh winsock reset
::do not need netsh winsock reset all, just netsh winsock reset
pause
goto:options



:ping
set /p host="Enter Host to ping: "
ping "%host%"
pause
goto options



:pingt
set /p host="Enter Host to ping: "
ping -t "%host%"
pause
goto options



:tracert
set /p host="Enter Host to tracert: "
tracert "%host%"
pause
goto options



:getmac
getmac
pause
goto options



:arp
echo  Displays and modifies the IP-to-Physical address translation 
echo  tables used by address resolution protocol (ARP).
echo.
echo  ARP -s inet_addr eth_addr [if_addr]
echo  ARP -d inet_addr [if_addr]
echo  ARP -a [inet_addr] [-N if_addr]
echo.
echo  -a      Displays current ARP entries by interrogating the current
echo          protocol data.  If inet_addr is specified, the IP and Physica
echo          addresses for only the specified computer are displayed.  If
echo          more than one network interface uses ARP, entries for each AR
echo          table are displayed.
echo  -g            Same as -a.
echo  inet_addr     Specifies an internet address.
echo  -N if_addr    Displays the ARP entries for the network interface specified
echo                by if_addr.
echo  -d      Deletes the host specified by inet_addr. inet_addr may be
echo          wildcarded with * to delete all hosts.
echo  -s      Adds the host and associates the Internet address inet_addr
echo          with the Physical address eth_addr.  The Physical address is
echo          given as 6 hexadecimal bytes separated by hyphens. The entry
echo          is permanent.
echo  eth_addr      Specifies a physical address.
echo  if_addr       If present, this specifies the Internet address of the
echo                interface whose address translation table should be modified.
echo                If not present, the first applicable interface will be used.
echo		Example:
echo	    arp -s 157.55.85.212   00-aa-00-62-c6-09  .... Adds a static entry.
echo	    arp -a                                    .... Displays the arp table.
echo.
echo.
echo.
echo.
set /p arpp=					"Enter Options From Above: "
arp "%arpp%"
pause
goto options



:hostname
hostname
pause
goto options



:nbtstat
nbtstat
goto options



:net
echo		=================================================================
echo		ACCOUNTS - COMPUTER - CONFIG - CONTINUE - FILE - GROUP - HELP
echo		HELPMSG - LOCALGROUP - NAME - PAUSE - PRINT - SEND - SESSION 
echo		SHARE - START - STATISTICS - STOP - TIME - USE - USER - VIEW 
echo		=================================================================
echo.
echo.
set /p netcmd=			     "Enter Option Above: "
net.exe "%netcmd%"
pause
goto options



:netsh
netsh 
goto options



:netstat
netstat
pause
goto options



:nslookup
set /p lookup="Please Specify Host To Lookup: "
nslookup "%lookup%"
pause
goto options



:pathping
echo	Usage: pathping [-g host-list] [-h maximum_hops] [-i address] [-n]
echo                [-p period] [-q num_queries] [-w timeout] [-P] [-R] [-T]
echo                [-4] [-6] target_name
echo.
echo	Options:
echo    -g host-list     Loose source route along host-list.
echo    -h maximum_hops  Maximum number of hops to search for target.
echo    -i address       Use the specified source address.
echo    -n               Do not resolve addresses to hostnames.
echo    -p period        Wait period milliseconds between pings.
echo    -q num_queries   Number of queries per hop.
echo    -w timeout       Wait timeout milliseconds for each reply.
echo    -P               Test for RSVP PATH connectivity.
echo    -R               Test if each hop is RSVP aware.
echo    -T               Test connectivity to each hop with Layer-2 priority tags.
echo    -4               Force using IPv4.
echo    -6               Force using IPv6.
echo.
echo.
echo.
set /p pping=			"Enter Options From Above: "
pathping %pping%
pause
goto options




:msconfig
%windir%\pchealth\helpctr\binaries\msconfig
goto options



:devicem
%windir%\system32\devmgmt.msc
goto options



:version
winver
goto options




:router
echo	(Current Supported Brands Are:)
echo.
echo.
echo	linksys
echo	d-link
echo	netgear
echo	belkin
echo	airlink
echo.
echo.
set /p router= "Enter The Brand Of Router You Want To Log-in To: "
echo.
echo.
echo.
echo.
echo.
if %router%==linksys	goto:linksys
if %router%==d-link	goto:dlink
if %router%==netgear	goto:netgear
if %router%==belkin	goto:belkin
if %router%==airlink	goto:airlink
pause
goto:options



:linksys
echo ( "Default username is "blank" password is "admin" )
echo.
echo.
echo.
pause
echo.
start http://192.168.1.1
goto options



:dlink
echo ( "Default username is "admin" password is "password" )
echo.
echo.
echo.
pause
echo.
start http://192.168.0.1
goto options



:netgear
echo ( "Default username is "admin" password is "blank" )
echo.
echo.
echo.
pause
echo.
start http://192.168.1.1
goto options



:belkin
echo ( "Default username is "blank" password is "blank" )
echo.
echo.
echo.
pause
echo.
start http://192.168.2.1
goto options



:airlink
echo ( "Default username is "blank" password is "admin" )
echo.
echo.
echo.
pause
echo.
start http://192.168.1.1
goto options


:exit
exit

Also I gave props to you over at my fav web show site on the forums in this thread:

http://forums.hak5.org/index.php/topic,8467.0.html

http://hak5.org check them out. Alot of good guys over there and a great show they show usually every 5th. of every month with lots of informative information. (If you haven't already been there before)

Thanks again man


----------



## TheOutcaste

It's those little typos that can drive you nuts, they are so obvious once you find them.
For troubleshooting, you may want to comment out the exit line. I find it easier to leave the window open while testing a script so I don't have to re-open a prompt.

If you are not going to add anything to the built in help, rather than using echo to display the command instructions you could just run the command with the help switch first, like for ARP just put this:


Code:


:arp
arp -?
echo.
set /p arpp=					"Enter Options From Above: "

On the netsh winsock reset command, don't know where the "all" part got started, nor why microsoft says the command is netsh winsock reset catalog (See here, search for netsh winsock: http://technet.microsoft.com/en-us/library/bb457156.aspx), as it seems to do the same thing with or without catalog (or all). Unless there is some way to reset individual LSP entries.
netsh winsock show catalog might be a useful addition.
As these netsh commands were added with Service Pack 2, you may want to check for that when the batch file first starts, then not display those options, or display an error if they do choose the option.
You can check for SP2 with this:


Code:


ECHO Processing please wait...
SystemInfo |FIND /I "Service Pack 2" >NUL
IF NOT ERRORLEVEL 1 (Set SP2=yes) ELSE (Set SP2=no)

I don't have a system without a SP installed, or with SP1 installed to check the systeminfo output. I suspect SP1 will say *Service Pack 1*, and the version line won't even have *Service Pack* in it if none is installed. So instead of a SP2 yes/no variable, you could set a SPNumber variable with 0, 1, or 2 to show the installed SP Level.


----------



## G-Stress

Ahhhh, yes. Thanks for the little addition and yea that will look much better using the commands with the -? option instead of echoing all the help. I think I tried to do it that way, but couldn't figure it out. Now I'm really frustrated trying to get something so simple to work.

I took a look at the first IP release/renew script you sent me and i tried to create just a simple .bat to do ping only



Code:


@echo off
:top

set /p host= "Enter host: " 
goto:ping
:ping
ping "%host%"
goto:top

I even tried this



Code:


@echo off
:top

set /p host= "Enter host: "  |ping "%host%"
::goto:ping
::ping

::goto:top

because "|" pipes the out put of (set /p host= ) to ping but now that I'm typing this and saying it to myself I guess "set /P" really isn't a command to pipe anything from to another command.

I just don't understand how it just loops when the only difference from the original is

forgot to add, what I mean by loops is it just keeps echoing "Enter host: " no matter what I type in it just keeps saying that.

if "%input%"=="ping" gotoing

but I told it to goto ping even after @echo off

I am liking that Service Pack Check addition I will definitely add it I'm also gonna add the ability to check OS Version actually... hmmm I already have a "windows version" option added so what i'll do is set it run automatically run first and depending on which version of windows it detects it will then decide which options to choose and that is gonna be sooo easy... I think 

I can't find the link I had. It the source to a .bat file to detect OS version, I got it bookmarked just can't remember which computer I think that'll be easy though.


----------



## devil_himself

Code:


:# OS Information
@echo off

for /f "tokens=3-5" %%a in ('reg query "HKLM\software\microsoft\windows nt\currentversion" /v ProductName ^| find "Microsoft Windows"') do (set os_=%%a %%b %%c)
for /f "tokens=3-5" %%i in ('reg query "HKLM\software\microsoft\windows nt\currentversion" /v csdversion ^| find "Service Pack"') do (set pack_=%%i %%j %%k)
echo.ProductName - %os_%
echo.CSDVersion - %pack_%


----------



## devil_himself

or try this

Start > Run > cmd > * wmic os get /?*



Code:


@echo off
WMIC OS GET ServicePackMajorVersion |FIND "2" >NUL
IF NOT ERRORLEVEL 1 (
      ECHO Service Pack 2 Installed
)ELSE (ECHO Service Pack 2 NOT Installed)


----------



## devil_himself

Try This One



Code:


@echo off
:top

set /p host=Enter host:  
goto:ping
:ping
if "%host%=="" echo .... & goto top
ping %host% -n 1
goto:top


----------



## G-Stress

@ devil_himself.

Ahhh... so this line here

if "%host%=="" echo .... & goto top

if "%host%=="" does the "" mean a nul value? Or anything the user enters it will try to ping it? If so I thought there might be a way to do this with a nul value, by nul I mean whatever was entered ping would try to ping it, but I was unsure.

I'm a little confused why the echo .... & goto top when goto:top is also at the bottom?


----------



## G-Stress

Oh thanks for the OS detection also  I'm gonna add that this weekend.


Oh and the ping bat didn't work. Even with echo on and a pause after ping %host% -n 1 the cmd prompt just closed out without error.


----------



## devil_himself

A little Mistake There .. Forgot The Quote



Code:


@echo off
:top

set /p host=Enter host:  
goto:ping
:ping
if "%host%"=="" echo Nothing Entered & goto top
ping %host% -n 1




> if "%host%"=="" does the "" mean a nul value?


Yes ... Nothing Typed .. Just Hitted Enter


----------



## TheOutcaste

G-Stress said:


> Code:
> 
> 
> @echo off
> :top
> 
> set /p host= "Enter host: "
> goto:ping
> :ping
> ping "%host%"
> goto:top


This works fine for me. If I just press enter the first time, it does *ping ""* which pings the name of the PC I'm using. This may be because I do have a WINS server on my network though. After the first time, pressing enter repeats the ping, and pressing enter doesn't change the host variable, so it's left with the same value it had before the set /p statement


G-Stress said:


> ...
> I even tried this
> 
> 
> 
> Code:
> 
> 
> @echo off
> :top
> 
> set /p host= "Enter host: "  |ping "%host%"
> ::goto:ping
> ::ping
> 
> ::goto:top
> 
> because "|" pipes the out put of (set /p host= ) to ping but now that I'm typing this and saying it to myself I guess "set /P" really isn't a command to pipe anything from to another command.


This just pings my local PC name. The set /p "output" is the prompt string, and it can be re-directed, but ping doesn't take "input". This command just does ping "" since host has not been defined, then waits for input. The host variable is never assigned a value for some reason though -- add a set statement right after the set /p to list all variables and host isn't in the list.
try *set /p host= "Enter host: " |find /I "host"* and you'll see that the prompt is piped to the find command, but the host variable is never set.



G-Stress said:


> ...I just don't understand how it just loops when the only difference from the original is
> 
> forgot to add, what I mean by loops is it just keeps echoing "Enter host: " no matter what I type in it just keeps saying that.
> 
> if "%input%"=="ping" gotoing
> 
> but I told it to goto ping even after @echo off
> 
> I am liking that Service Pack Check addition I will definitely add it I'm also gonna add the ability to check OS Version actually... hmmm I already have a "windows version" option added so what i'll do is set it run automatically run first and depending on which version of windows it detects it will then decide which options to choose and that is gonna be sooo easy... I think
> 
> I can't find the link I had. It the source to a .bat file to detect OS version, I got it bookmarked just can't remember which computer I think that'll be easy though.


Only gets hard if you need to pin down which Win95 version is running.

Don't know why yours is just looping, it seems to work just fine for me.


----------



## TheOutcaste

devil_himself said:


> Code:
> 
> 
> :# OS Information
> @echo off
> 
> for /f "tokens=3-5" %%a in ('reg query "HKLM\software\microsoft\windows nt\currentversion" /v ProductName ^| find "Microsoft Windows"') do (set os_=%%a %%b %%c)
> for /f "tokens=3-5" %%i in ('reg query "HKLM\software\microsoft\windows nt\currentversion" /v csdversion ^| find "Service Pack"') do (set pack_=%%i %%j %%k)
> echo.ProductName - %os_%
> echo.CSDVersion - %pack_%


Thanks devil_himself, I knew there was an easy way to read it from the registry, but couldn't find it it quickly.:up:

Nice thing with this is it will work on Win2K and WinNT 4.0 (SP# only) where systeminfo won't.
You do have to have installed the Win2K Support tools from the CD or the NT 4.0 Resource kit, as reg.exe was not included by default.
For NT you have to make one small change as the default delimiters for the FOR command were comma and space instead of tab and space.


Code:


Change
"tokens=3-5"
to
"tokens=3-5 delims=	 " (tab followed by a space)

Otherwise pack_ gets set to *Pack #* instead of *Service Pack #*

Jerry


----------



## G-Stress

The ping .bat is still not wanting to work for some reason. Everything i've tried previously it either will just keep printing to the screen

Enter Host:

or whenever enter is pressed it will just close. Regardless of echo is on or off or if there is a pause inserted. I even just tried:



Code:


@echo off
:top

set /p host=Enter host:  
goto:ping
:ping
if "%host%"=="" 
%windir%\system32\ping.exe %host% -n 3
pause
goto:top

Still not working. It just automatically closes the cmd. Let me try on a different computer and see what happens.


----------



## G-Stress

Thought I'd add, maybe I done something totally wrong, because even in the complete script now when I try to "ping" it does the same thing, now matter what I type then hit enter it just keeps repteating
Enter Host:


----------



## TheOutcaste

That's bizarre.
I copied the code from your last post, added the goto:top for the IF command that is missing, so it looks like this (my changes in red):


Code:


[COLOR="Red"][B]rem[/B][/COLOR] @echo off
:top
set /p host=Enter host:  
goto:ping
:ping
if "%host%"==""[COLOR="Red"][B] goto:top[/B][/COLOR]
%windir%\system32\ping.exe %host% -n 3
pause
goto:top

and this is the output (orange is the line from the file, regular text is the output, blue is user input):


Code:


C:\Scripts>ptest

C:\Scripts>[B][COLOR="DarkOrange"]rem @echo off[/COLOR][/B]

C:\Scripts>[B][COLOR="DarkOrange"]set /p host=Enter host:[/COLOR][/B]
Enter host: [B] [COLOR="Blue"]yahoo.com[/COLOR][/B]

C:\Scripts>[B][COLOR="DarkOrange"]goto:ping[/COLOR][/B]

C:\Scripts>[B][COLOR="DarkOrange"]if "yahoo.com" == "" goto:top[/COLOR][/B]

C:\Scripts>[B][COLOR="DarkOrange"]C:\WINDOWS\system32\ping.exe yahoo.com -n 3[/COLOR][/B]

Pinging yahoo.com [66.94.234.13] with 32 bytes of data:

Reply from 66.94.234.13: bytes=32 time=32ms TTL=55
Reply from 66.94.234.13: bytes=32 time=32ms TTL=54
Reply from 66.94.234.13: bytes=32 time=36ms TTL=55

Ping statistics for 66.94.234.13:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 32ms, Maximum = 36ms, Average = 33ms

C:\Scripts>[B][COLOR="DarkOrange"]pause[/COLOR][/B]
Press any key to continue . . .

C:\Scripts>[B][COLOR="DarkOrange"]goto:top[/COLOR][/B]

C:\Scripts>[B][COLOR="DarkOrange"]set /p host=Enter host:[/COLOR][/B]
Enter host: [B][COLOR="Red"]I pressed Enter here, which won't change the value of host[/COLOR][/B]

C:\Scripts>[B][COLOR="DarkOrange"]goto:ping[/COLOR][/B]

C:\Scripts>[B][COLOR="DarkOrange"]if "yahoo.com" == "" goto:top[/COLOR][/B] [B][COLOR="Red"]Note that %host% is still yahoo.com[/COLOR][/B]

C:\Scripts>[B][COLOR="DarkOrange"]C:\WINDOWS\system32\ping.exe yahoo.com -n 3[/COLOR][/B]

Pinging yahoo.com [66.94.234.13] with 32 bytes of data:

Reply from 66.94.234.13: bytes=32 time=31ms TTL=55
Reply from 66.94.234.13: bytes=32 time=32ms TTL=54
Reply from 66.94.234.13: bytes=32 time=33ms TTL=54

Ping statistics for 66.94.234.13:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 31ms, Maximum = 33ms, Average = 32ms

C:\Scripts>[B][COLOR="DarkOrange"]pause[/COLOR][/B]
Press any key to continue . . .
Terminate batch job (Y/N)? y

Adding a *set host=* line right after the *ing* label takes care of the case where something is entered the first time, then enter is pressed on a 2nd or later pass.

I even tried this in command.com. It failed there because the WINDIR variable is not passed to command.com, so you have to specify c:\ instead of %windir% for the ping command, or don't specify the path at all. The following worked in both cmd.exe and command.com:


Code:


rem @echo off
:top
set host=
set /p host=Enter host:  
goto:ping
:ping
if "%host%"=="" goto:top
ping %host% -n 3
pause
goto:top

Running this in a cmd prompt with command extensions disabled will either just loop continuously and won't let you enter anything if you have the echo off command commented out. If it's enabled, it just sits there until you press CTRL+C, as set /p host=Enter host: becomes a command to set the variable */p host* to the value *Enter host*, so host is always equal to "" and it just loops.

You might try using echo or pause to output line numbers, and add a few set commands to see what the variables are doing as you go along, something like the following:


Code:


:top
@echo line 1
set host=
@echo line 2
set h
@echo line 3
color fc
set /p host=Enter host:  
@echo line 4
set h
color f0
@echo line 5
goto:ping
@echo line 6
:ping
@echo line 7
if "%host%"=="" goto:top
@echo line 8
ping %host% -n 3
@echo line 9
pause
@echo line 10
goto:top

hth

Jerry


----------



## G-Stress

hmmmm... none of the above mentioned worked for me on 2 different PC's running XP Pro SP2, however the original does still work in Vista for some reason. I also tried this in XP to verify it wasn't a code issue



Code:


rem @echo off
:top
set host=
set /p host=Enter host:  
goto:ping
:ping
if "%host%"=="yahoo.com" goto:go
:go
ping %host% -n 3
pause
goto:top

Now that did not work in XP didn't try Vista, because the original worked. What does happen, is it outputs this

ping yahoo.com -n 3

Then drops down and says (Enter Host again then when I enter anything at all and hit enter it closes the cmd. This is definitely an issue with XP and I believe I did some windows updates on both these machines, let me try my 2k3 machine and I'll post results from that.

Also cmd extensions were enabled as well. if I disable them, then as soon as I run my ipconfig.bat script it automatically acts as if I entered a invalid character and loops a "pause" and keeps saying please choose from one of the options at top.

Followed this link here on the cmd extensions:

http://www.windowsnetworking.com/kb...ide/EnableDisableCommandpromptextensions.html


----------



## G-Stress

This issue appears to be only with "ping" command and so far only on XP. Everything else works still just fine. In Vista everything is working without prob so far.


----------



## TheOutcaste

G-Stress said:


> hmmmm... none of the above mentioned worked for me on 2 different PC's running XP Pro SP2, however the original does still work in Vista for some reason. I also tried this in XP to verify it wasn't a code issue...


So the following didn't work? Where did it fail? Is it showing that the host variable is getting properly set to what you enter? (I removed the color statements, didn't mean to leave them in on previous post, was trying to color just one line).
If should display each line followed by a separate line with the line number. The set h command should display all variables that start with H. The Line 6 is the only one that should never be seen, as it follows the goto.



Code:


:top
@echo line 1
set host=
@echo line 2
set h
@echo line 3
set /p host=Enter host:  
@echo line 4
set h
@echo line 5
goto:ping
@echo line 6
:ping
@echo line 7
if "%host%"=="" goto:top
@echo line 8
ping %host% -n 3
@echo line 9
pause
@echo line 10
goto:top

Jerry


----------



## G-Stress

hmmm... still doing the same thing... this is sooo weired that it is just with the ping command. Sorry I did forget to try this previously, but this was my output:



Code:


line 1

C:\Documents and Settings\USERNAME\Desktop>set host=
line 2

C:\Documents and Settings\USERNAME\Desktop>set h
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\USERNAME
line 3

C:\Documents and Settings\USERNAME\Desktop>set /p host=Enter host:
Enter host:  yahoo.com
line 4

C:\Documents and Settings\USERNAME\Desktop>set h
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\USERNAME
host=yahoo.com
line 5

C:\Documents and Settings\USERNAME\Desktop>goto:ping
line 7

C:\Documents and Settings\USERNAME\Desktop>if "yahoo.com" == "" goto:top
line 8

C:\Documents and Settings\USERNAME\Desktop>ping yahoo.com -n 3
Enter host:

It's like it does pass the variable to ping, but ping does not execute


----------



## TheOutcaste

try:
*ping.exe %host% -n 3
%SystemRoot%\system32\ping %host% -n 3
%SystemRoot%\system32\ping.exe %host% -n 3*
and see if all three work, or just one or two of them.

I suspect you have an executable file named ping.??? (where ??? is com, bat, or cmd) that is being found before C:\Windows\system32\ping.exe. If you have a ping.com, ping.bat or ping.cmd file that is being found in the current folder or on the path before C:\Windows\system32, it will run instead of C:\Windows\system32\ping.exe. Ping.com would run before ping.exe, even if they are in the same folder, and if you've happened to have changed the pathext variable so that .bat comes before .exe, ping.bat would run before ping.exe as well.

look at *set path* to see your path and pathext variables
default for PATHEXT:
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

Check your *C*urrent *W*orking *D*irectory (*CWD*, looks like C:\Documents and Settings\USERNAME\Desktop in this case), then each folder in order as found on the PATH= line and see if there is a ping.com, ping.bat, or ping.cmd found before you get to C:\Windows\system32. C:\Windows\system32 is usually first on the path statement, but if you or some program has put something before it, weird and unexpected stuff can happen.

Jerry


----------



## G-Stress

@ Jerry,

You were right it was because I had a ping.bat file on my desktop and then my test.bat file on my desktop which is what I kept debugging with trying to get it working, because I found



Code:


set /p host= Enter Host:
ping.exe %host%
pause




Code:


set /p host= Enter Host:
%windir%\system32\ping %host%
pause

both worked, then just today right before I read this post on the other forums I check frequently they mentioned this also. You did explain clearly the "path" to me I got a good understanding of how all that works now. I was curious of how in cmd if it defaulted to "Documents and Settings" how it just know where to call ping from, but now I know and understand so thanks alot for all the very good advice and for being so patient and helpful. Your the man


----------



## G-Stress

This little utility has become quite useful to me and alot of my friends. One thing I was wondering was is there a way I can set it so that when executed the cmd window opens "larger" or maximized. 

Reason y is because when I run it, it cuts off the top part and I have to scroll up to see option #1 and so forth.


----------



## Squashman

http://www.stahlforce.com/dev/index.php?tool=winshell&back=dev

Then on the shortcut tab you would put this in the Target Box.
%SystemRoot%\system32\cmd.exe /Q /K pingtest.bat

The path to cmd.exe should already be there. You just need to add the switches and the batch file you want to execute.


----------



## TheOutcaste

Rather than copy the Command Prompt shortcut, you can just make a shortcut to the batch file and set properties from there.

You can also modify default properties for all batch file you start from the Run box or by double clicking. When any batch file window is on the screen, click the Control Icon in the upper left corner (or hit ALT+Spacebar) then click properties. Set the window properties as you want from the *Layout* tab, and choose *Save properties for future windows with same title* when you exit the properties window.

HTH

Jerry


----------



## G-Stress

Thanks guys, that does help alot for just myself, but I've shared this utility with quite a few friends via a usb stick that they use for troubleshooting in different pc's and I didn't know if it were possible to set the prog itself to always open in a window bigger then the standard.

I used quick batch file compiler to convert to .exe if that helps any. Again thanks for the quick responses and all the help. I'm feeling good and a bit buzzed right now so I hope i'm making sense and I hope one day I can give back some help in this area


----------



## TheOutcaste

Should be able to put the shortcut with the layout settings on the USB stick, then just make sure they run it via the shortcut rather than directly.

GL

Jerry


----------



## G-Stress

hmmm... okay I may go that route. Here is the source of what I have for now in case anyone else in interested. I'm also in the process of trying to learn VB and C and re-write it there with a nice gui.



Code:


@echo off
title IP Config v1.2
:options
echo =========================
echo IPCONFIG v1.2 By G-Stress
echo =========================
echo.
echo %date%
echo %time%
echo.
echo =====================
echo IP MENU OPTIONS:
echo =====================
echo 1.   ipconfig
echo 2.   ipconfig all
echo 3.   release
echo 4.   renew
echo 5.   flushdns
echo 6.   reset winsock
echo 7.   ping
echo 8.   ping -t (continious ping ctrl+c to stop)
echo 9.   tracert
echo 10.  getmac
echo 11.  arp
echo 12.  hostname
echo 13.  nbtstat
echo 14.  net
echo 15.  netsh
echo 16.  netstat
echo 17.  nslookup
echo 18.  pathping
echo 19.  router login
echo 20.  windows version
echo 21.  msconfig
echo 22.  device manager
echo 23.  modem login
echo 24.  services
echo =====================
echo   q to quit
echo =====================
set /p input="Enter Options Here: "
echo.
echo.
echo.

if "%input%"=="1" 	goto:ipconfig
if "%input%"=="2" 	goto:ipconfigall
if "%input%"=="3" 	goto:release
if "%input%"=="4" 	goto:renew
if "%input%"=="5" 	goto:flushdns
if "%input%"=="6" 	goto:winsock
if "%input%"=="7" 	goto:ping
if "%input%"=="8" 	goto:pingt
if "%input%"=="9" 	goto:tracert
if "%input%"=="10" 	goto:getmac
if "%input%"=="11" 	goto:arp
if "%input%"=="12" 	goto:hostname
if "%input%"=="13" 	goto:nbtstat
if "%input%"=="14"	goto:net
if "%input%"=="15"	goto:netsh
if "%input%"=="16"	goto:netstat
if "%input%"=="17"	goto:nslookup
if "%input%"=="18"	goto:pathping
if "%input%"=="19"	goto:router
if "%input%"=="20"	goto:version
if "%input%"=="21"	goto:msconfig
if "%input%"=="22"	goto:devicem
if "%input%"=="23"	goto:modem
if "%input%"=="24"	goto:services
if "%input%"=="q" 	goto:exit

echo Please choose from the Options listed above!
echo.
echo.
pause
goto:options



:ipconfig
ipconfig.exe
pause
goto:options



:ipconfigall
ipconfig.exe /all
pause
goto:options



:release
ipconfig.exe /release
pause
goto:options



:renew
ipconfig.exe /renew
pause
goto:options



:flushdns
ipconfig.exe /flushdns
pause
goto:options



:winsock
netsh winsock reset
::do not need netsh winsock reset all, just netsh winsock reset
pause
goto:options



:ping
set /p host="Enter Host to ping: "
ping.exe "%host%"
pause
goto options



:pingt
set /p host="Enter Host to continously ping: (ctrl+c to stop)"
ping.exe -t "%host%"
pause
goto options



:tracert
set /p host="Enter Host to tracert: "
tracert "%host%"
pause
goto options



:getmac
getmac
pause
goto options



:arp
arp /?
pause
echo.
echo.
echo.
echo.
set /p arpp=					"Enter Options From Above: "
arp "%arpp%"
pause
goto options



:hostname
hostname
pause
goto options



:nbtstat
nbtstat
goto options



:net
echo		==============================================================
echo		ACCOUNTS - COMPUTER - CONFIG - CONTINUE - FILE - GROUP - HELP
echo		HELPMSG - LOCALGROUP - NAME - PAUSE - PRINT - SEND - SESSION 
echo		SHARE - START - STATISTICS - STOP - TIME - USE - USER - VIEW 
echo		==============================================================
echo.
echo.
echo.
set /p netcmd=			     "Enter Option Above: "
net.exe "%netcmd%"
pause
goto options



:netsh
netsh
goto options



:netstat
netstat
pause
goto options



:nslookup
set /p lookup="Please Specify Host To Lookup: "
nslookup "%lookup%"
pause
goto options



:pathping
pathping /?
echo.
echo.
echo.
echo.
set /p pping=			"Enter Options From Above: "
pathping %pping%
pause
goto options




:msconfig
%windir%\pchealth\helpctr\binaries\msconfig
goto options



:devicem
%windir%\system32\devmgmt.msc
goto options



:version
winver
goto options




:router
echo	(Current Supported Brands Are:)
echo.
echo.
echo	1. linksys
echo	2. d-link
echo	3. netgear
echo	4. belkin
echo	5. airlink
echo	6. comcast smc gateway
echo.
echo.
set /p router= "Enter The Brand Of Router You Want To Log-in To: "
echo.
echo.
echo.
echo.
echo.
if %router%==1	goto:linksys
if %router%==2	goto:dlink
if %router%==3	goto:netgear
if %router%==4	goto:belkin
if %router%==5	goto:airlink
if %router%==6  goto:comcast
pause
goto:options



:linksys
echo ( "Default username is "blank" password is "admin" )
echo.
echo.
echo.
pause
echo.
start http://192.168.1.1
goto options



:dlink
echo ( "Default username is "admin" password is "password" )
echo.
echo.
echo.
pause
echo.
start http://192.168.0.1
goto options



:netgear
echo ( "Default username is "admin" password is "password" )
echo.
echo.
echo.
pause
echo.
start http://192.168.1.1
goto options



:belkin
echo ( "Default username is "blank" password is "blank" )
echo.
echo.
echo.
pause
echo.
start http://192.168.2.1
goto options



:airlink
echo ( "Default username is "blank" password is "admin" )
echo.
echo.
echo.
pause
echo.
start http://192.168.1.1
goto options


:comcast
echo ( "Default username is "mso" password is "D0nt4g3tme" ) for first time login only
echo.
echo.
echo ( "Customer login is "custadmin" password "highspeed" )


:modem
start http://192.168.100.1
goto options


:services
services.msc
goto options


:exit
exit

Mad kudos to TheOutcaste and everyone else who helped and gave input


----------



## Squashman

There are tons of graphical utilities that can do most of what you have above already.
What is the point of leaving your router passwords set to the default. I don't think the default router info you have above is necessarily the same for all models of a certain manufacturer. That is just from my experience.


----------



## G-Stress

@ Squashman

True and I don't leave anything default. This is just a basic troubleshooting utility I wanted to create for a few friends that aren't as savy to help them troubleshoot. I only decided to create this instead of using a commercial utility to learn more about coding @ the cmd line and to see if I could do it. It was alot of fun learning during the creation of this.


----------

