Read Time:2 Minute, 6 Second

Here we are again, trying to make a device work from one center to another. Each center has the same server IP address but different subnets. All the subnets are /24. So, that makes life easier. All of them are .5 as well. So, that makes life much easier. So, how do we get a website started on .5 from every device but able to take it to another site? Well, the solution is simple. You find the IP address and tell the internet browser to start it for you.

First lets get the IP address and sort through it.

for /f "usebackq tokens=2 delims=:" %%f in (`ipconfig ^| findstr /c:"IPv4 Address"`) do set "ip=%%f"

The above is a loop for IP config to remove anything that is ipv6 to IPv four. Once we have our IPv4 Address we then loop through that and set each octet that we want to use.

for /f "tokens=1-4 delims=. " %%a in ("%ip%") do (
set octetA=%%a
set octetB=%%b
set octetC=%%c
set octetD=%%d
)

We sort through the IPv4 address and split each item via the . delimiter. Now we take that info and start our IE.

start "CMD" /D "C:\Windows\System32\" /max "C:\Program Files\Internet Explorer\iexplore.exe" "http://%octetA%.%octetB%.%octetC%.5/LocalWebsite/"

That’s it, a very simple process, but it can help with so much time.

The Script

@echo off
rem All i need to do now is grab only the IP address with batch. 
rem ipconfig | find "IPv4"
for /f "usebackq tokens=2 delims=:" %%f in (`ipconfig ^| findstr /c:"IPv4 Address"`) do set "ip=%%f"

for /f "tokens=1-4 delims=. " %%a in ("%ip%") do (
set octetA=%%a
set octetB=%%b
set octetC=%%c
set octetD=%%d
)

start "CMD" /D "C:\Windows\System32\" /max "C:\Program Files\Internet Explorer\iexplore.exe" "http://%octetA%.%octetB%.%octetC%.5/LocalWebsite/"
exit

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *