create a bat file

Asked

Viewed 158 times

-1

I need to create a file bat to change the network card’s ip and then open the cmd with a few command lines.
In this case it would be something like this:

  • Change the ip
  • Open the cmd
  • Place necessary command lines.

Until opening the cmd I’ve done it but I can’t get it to write there afterwards, someone can help.

netsh interface ip set address name="Ethernet" static 192.168.1.1 255.255.255.0

start /max "cmd.exe"

ssh [email protected]

12345678

2 answers

3


• If I understand the question, may I suggest that you use a bat to create a second bat and call that second one using the start /max already finishing the first bat...


@echo off  && >nul chcp 1252 & type nul >"%temp%\bat_to_bat.bat"
:: alterando o IP:

rem :: Configurando IP: 192.168.1.100 ^| Mascara: 255.255.255.0 ^| Gateway: 192.168.1.1
netsh interface ip set address name="Ethernet" static 192.168.1.100 255.255.255.0 192.168.1.1
rem :: Configurando DNS Primario: 1.1.1.1
netsh interface ip add dns "Ethernet" 1.1.1.1
rem :: DNS Secundario: 1.0.0.1
netsh interface ip add dns "Ethernet" 1.0.0.1 index=2

>"%temp%\bat_to_bat.bat"^
   (
    echo/    @echo off & color 0a
    echo/    ssh [usuário]@192.168.1.1
    echo/    [Senha]
   ) && start /max cmd.exe /k call "%temp%\bat_to_bat.bat" <nul & exit /b

Or with all the shares in one bat calling cmd and executing commands...4


@echo off && >nul chcp 1252 & type nul >"%temp%\bat_to_bat.bat"

>"%temp%\bat_to_bat.bat"^
    ( 
     echo/    @echo off & color 0a
     echo/    rem :: Configurando IP: 192.168.1.100 ^| Mascara: 255.255.255.0 ^| Gateway: 192.168.1.1
     echo/    netsh interface ip set address name="Ethernet" static 192.168.1.100 255.255.255.0 192.168.1.1
     echo/    rem :: Configurando DNS Primario: 1.1.1.1
     echo/    netsh interface ip add dns "Ethernet" 1.1.1.1
     echo/    rem :: DNS Secundario: 1.0.0.1
     echo/    netsh interface ip add dns "Ethernet" 1.0.0.1 index=2
     echo/    ssh [usuário]@192.168.1.1
     echo/    [senha]
     echo/
    ) && start /max cmd.exe /k call "%temp%\bat_to_bat.bat" <nul & exit /b

• Obs.:

  1. Edit/adjust the line with the ips netsh interface ip...

  2. The bat needs to run as Administrator

  • I liked the technique of grouping the commands with "(" and ")" to create another file...normally I put ">" and then ">>" in each line...this technique I know from bash (where "(" and ")" delimit a sub-shell) but never thought of using in cmd

0

only need to open cmd with the /C command, everything after the /c is copied to console.

example:

start cmd /C ping 10.0.0.1 -t

Browser other questions tagged

You are not signed in. Login or sign up in order to post.