1

I'm looking for a simple script or batch method for checking the existence of a specific IP address (being moved between machines via NETSH) on the local network card. I need to start up certain services / apps etc ONLY if the specified IP address exists on the card.

Any ideas?

Thanks.

Martin M.
  • 6,428
  • 2
  • 24
  • 42
Codmental
  • 11
  • 1
  • 2

2 Answers2

1

powershell? save this as a .ps1 script and execute. (substitute the IP address you care about...)

$ipaddr = Get-WMIObject win32_NetworkAdapterConfiguration | Where-Object {$.IPEnabled -eq $true } | Foreach-Object { $.IPAddress } if ($ipaddr -eq "10.10.10.10") { "Yes it's here" } else { "Nope" }

Bob
  • 597
  • 2
  • 8
  • That's great, I'm finding Powershell extremely useful but have a long way to go in being able to come up with solutions like this. Thanks very much. – Codmental Jun 10 '11 at 07:43
0

Here's a batch script that uses ipconfig, parses the output for the ip address you specified. Then tells you if it was found or not.

To use it: paste the code into notepad saveas .bat file and execute it. Change the ip address to the one you want.

set ip=192.168.1.1

ipconfig | find /i "%ip%" > nul
if %errorlevel% equ 0 (echo ip address found) else (echo ip address not found)
JamesBarnett
  • 1,129
  • 8
  • 12