Http Static Web Server在任意电脑上绑定ip(批处理)
我们的静态网页采用Http Static Web Serverhttps://sws.joseluisq.net/examples/http1/。
在其他机器上访问该静态server,就需要命令行直接用参数绑定ip --host xx.xx.xx.xx(ip address)。
static-web-server.exe -g debug -d .\build -f .\assets -p %port% --host %ipAddr%
如果需要在任意机器上绑定ip呢?只能用批处理的方式计算出当前ip是多少。
for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr IPv4') do (
set ipAddr=%%i
)
结果为
解释:
执行命令ipconfig之后,结果中有一行IPv4 Address. . . . . . . . . . . : 1x.1xx.1xx.8x,用findstr IPv4找到它。
使用for循环将这一行按:截断,取tokens 2nd第二个,即ip地址。

浙公网安备 33010602011771号