Time left in Bush's term

Days

Hours

Min.

Sec.
Countdown clock provided by BushsLastDay.com

Project Insomnia

Project Insomnia is many things, but in this context it is simply a "braindump" of whatever I happen to be thinking/reading/watching/doing at the moment. Parental guidance suggested.

Tuesday, June 06, 2006

Unnecessarily complicated

Sure, you could do ipconfig /all, look for the DNS Servers line and type it after ping -t. Sure, if you're a loser! You might as well just wait on your ISP's level-1 tech support line for two or three hours, just to find out that your DSL is down either at the DSLAM or the POP.

Instead, try this:
for /F "tokens=2 delims=:" %a in ('ipconfig /all ^| find /i "DNS Servers"') do ping -t %a
(That should be all one line.)

Expanded:
  1. ipconfig /all prints the current TCP/IP configuration.

  2. ^| pipes the output of the previous command to the next command. See the linked article for why the caret is required before the pipe.

  3. find /i searches the following quoted text, case-insensitive.

  4. "DNS Servers" is from the output of ipconfig /all.

  5. for /F "tokens=2 delims=:" %a in takes the output from the previous elements (typically something like DNS Servers . . . . . . . . . . . : 64.81.79.2), parses it into tokens delimited by a colon, selects the second token and places the result into the named variable %a.

  6. do is the "execute" part of for; whatever command follows is run with the parsed parameters.

  7. ping -t sends ICMP ECHO requests to the target IP address; the -t parameter causes the pings to continue until interrupted with Ctrl-C.

All clear? Isn't that better? I'm just saying.

By the way, this is not meant to impugn Speakeasy's most excellent tech support people. Yes, my DSL has flakier than Marie Callender's finest crust for the past few days, but it's not Speakeasy's fault and they're managing the diagnostic/repair process through Covad and AT&T.

Oh, and if you want to put this in a batch file, you'll need to double the percent signs in front of the variable. Like this:
for /F "tokens=2 delims=:" %%a in ('ipconfig /all ^| find /i "DNS Servers"') do ping -t %%a
|| Andrew, 8:32 PM || ||

"Project Insomnia" and "project-insomnia.com" ™ & SM; site contents © Andrew Rich except where noted.