기술 노트/Windows
출력문에서 필드 변수 선언하기
미래의억만장자
2024. 1. 18. 23:07
ip 주소를 cmd 창에서 입력을 하려고 하는데, 랜카드 이름을 지정할 수 있는 방법이 없을까 찾아보다 스크립트로 확인할 수 있는 방법을 찾아 기록합니다.
@echo on
chcp 949
for /f "tokens=5,6 delims= " %%a IN ('netsh interface ipv4 show interface ^| findstr 이더 ^| findstr /v dis') do set result=%%a %%b
if "%result%" =="이더넷 " (
for /f "tokens=5 delims= " %%a IN ('netsh interface ipv4 show interface ^| findstr 이더 ^| findstr /v dis') do set result1=%%a
echo netsh interface ipv4 set address name="%result1%" static 192.168.100.161 255.255.255.0 192.168.100.1
echo netsh interface ipv4 set dns name="%result1%" static 8.8.8.8
echo netsh interface ipv4 add dns name="%result1%" 8.8.4.4 index=2
) else (
echo netsh interface ipv4 set address name="%result%" static 192.168.100.161 255.255.255.0 192.168.100.1
echo netsh interface ipv4 set dns name="%result%" static 8.8.8.8
echo netsh interface ipv4 add dns name="%result%" 8.8.4.4 index=2
)