windows - How to replace hostname with IP address in a network drive path using batch command -
set sourcedir=\\my_server\path if "%sourcedir:~0,2%"=="\\" ( set sourcehost= rem not sure do. here need isolate hostname /f "tokens=2" %%b in ('nslookup %sourcedir%^|find /i "address"') set ser_ip=%%b rem here need replace my_server %ser_ip% ) in code i'm trying replace host-name ip address in network path.
- in
set sourcehost= rem not sure do. here need isolate hostnameline need isolate hostname path - in
rem here need replace my_server %ser_ip%line need replace host name retrieved ip address
if nslookup ip adress 10.12.13.14 last result should \\10.12.13.14\path please me these 2 lines. thank you!
i'd go ping instead of nslookup. if there ipv6 addresses more difficult parse , ping has -4 option.
ip easy extract enclosed in square brackets.:
@echo off&setlocal enableextensions enabledelayedexpansion set "sourcedir=\\my_server\path" if "%sourcedir:~0,2%"=="\\" ( /f "delims=\" %%h in ( "%sourcedir%" ) /f "tokens=2delims=[]" %%b in ('ping -n 1 -4 %%h^|find "["' ) set "sourcedir=!sourcedir:%%h=%%b!" ) echo %sourcedir%
Comments
Post a Comment