Been there, done that.
First check/wait if your network is actually connected in the 1st place and if you have TCPIP up. (In case of Wifi connecting after the login your script may start before the Wifi is actually working.)
The "ipconfig" output (WITHOUT the /all parameter) will only show interfaces that are UP and will provide the ip-address of the default gateway.
Then ping that default gateway, which should be your router (I assume that is always on).
Then grep the output of "arp -a" to see if the MAC-address of your router is there. (If you use both wired and wireless check for both MAC-addresses. They are probably NOT the same.)
This MAC-address check also catches the case where you are on someone else's network where the router happens to have the same ip-address as you have at home.
And there is no need to do this 4 times with delays (I presume that is an attempt to get the HTPC out of power-sleep if needed). Just 1 ping (which under Windows does 4 pings with 1 second delay anyway) to the router is enough.
The router will either respond (so you can check the MAC) or it doesn't in which case something is really wrong with the network and it is unusable anyway.
Code below is tested on Windows 10. I'm fairly certain it will work on any Windows NT version.
@echo off
set mymac=ac-9e-17-96-6e-60
set delayedexpansion=on
rem Pull the default gateways from ipconfig and extract the one with a value.
rem Carefull! There is 1 extra space before the ip-address.
for /F "delims=: tokens=2 usebackq" %%a in ( `ipconfig ^| find /I "default gateway"` ) do (
if NOT "%%a."==" ." set IP=%%a
)
echo Default gateway:%IP%
rem Ping it to make sure it appears in arp -a output
ping -n 1 %IP% >nul
rem Filter the line with the ip-address and MAC from arp -a and take action if found
arp -a | find /I "%IP%" | find /I "%mymac%"
if errorlevel 1 (echo Not found: Not at home) else ( echo I'm at home)
Could you do something like this: http://pastebin.com/rTFNtp75 where you add your home router mac address as the variable $mac. You can get this from running
– HelpingHand – 2017-03-19T14:33:08.437arp -a
@EMK That is basically what I wrote in my answer, but using some PowerShell/WMI dark magic. It can be done with just CMD commands (ipconfig/find/arp and using FOR to parse the deault gateway from the ipconfig info.) – Tonny – 2017-03-19T16:44:35.980