I have a .bat file which starts a bunch of processes, ultimately resulting in bringing online an ftp server on my local machine. As a last step, I would like the .bat file to start my browser directed at this ftp server. Since the goal is to select a file and then copy-paste the URL to someone else, I need it to point to my actual 开发者_如何学GoIP address and not "localhost" (localhost obviously shows me the files but doesn't help me share them). Unfortunately, the computer is configured for DHCP, and the IP changes with almost every reboot.
In other words, I want the last two lines of my .bat file to say:
set IP=[my IP address]
chrome "http://%IP%:8080"
How do I actually get my IP address in a .bat file? Apparently it's not easy.
Before we try too hard, does chrome http://127.0.0.1:8080
work?
Alternatively, this code works for me:
@Echo Off
For /F "delims=: skip=2 tokens=1,2" %%a In ('NetSh Interface IPv4 Show Addresses "Local Area Connection"') Do Call :ReadLine "%%a" %%b
Chrome http://%IP%:8080
Exit /B
:ReadLine
If Not %1==" IP Address" Exit /B
Set IP=%2
Exit /B
You'll probably need to tweak it. NetSh Interface IPv4 Show Addresses
may produce different formatting on different operating systems. I use Windows 7.
精彩评论