Microsoft > Microsoft DOS

how can i copy and replace sting in a txt file

(1/2) > >>

mioo_sara:
hi  to  all  i  have a  text file  that  contain an  ip  but  should  be  update  every day  for  an vpn  how  can  i replace  this  ip  in  a txt  file  with   another  one

my ip.txt  file  contain  this


--- Quote --- 192.168.233.188       4e-53-d0-68-34-bf     dynamic   
(@ECHO OFF
ECHO Configuring Proxy Settings please wait...
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d  192.168.158.134:8080 /f
EXIT
--- End quote ---

i  want first  line (192.168.233.188) just  this  one replace  with  ip  in  5th  line  (192.168.158.134)

attention==  first  line  ip  will  change  every  day

how  can  i do  it  can  you  help?

i  batch  script  could  be  very  nice
thanks

Hackoo:
Hi !
First question : How did you get the ip and save it into config.txt ?
EDIT :
If I presume that you get the IP from the command line ARP -A in the first line
You can do something like that without using the config.txt

--- Code: ---@echo off
Title Change VPN Settings
for /f "tokens=2" %%a in ('arp -a ^| findstr /i "\<Interface\>"') do set IP=%%a
echo The IP address is %IP%
pause
ECHO Configuring Proxy Settings please wait...
ECHO REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
ECHO REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d  %IP%:8080 /f
pause
--- End code ---
Note : I added the command ECHO To be sure if the IP is correct, then you can remove every ECHO before the command REG ADD

mioo_sara:
thanks  dear Hackoo
your  cod is  working  but i  am  using  vpn from my  mobile  phone  for  my  laptop  pc  so 
i get  my  new  ip in  this  way


--- Quote ---@echo off
REM clear arp cache (optional):
arp -d
REM ask everybody on the subnet for a response:
for /l %%a in (1,1,255) do start /b ping -n 2 -w 500 192.168.1.%%a >nul
REM wait for the processes to finish:
timeout 2 >nul
REM show the responses (with IP and MAC):
arp -a>mynew-ip.txt
pause
--- End quote ---


in  mynew-ip.txt  i  have this

--- Code: ---Interface: 192.168.11.181 --- 0xc
  Internet Address      Physical Address      Type
  192.168.11.49           4e-53-d0-68-34-bf     dynamic   
--- End code ---

192.168.11.49==== is  my  new  working  ip  that  i  need  every  day so  you  should  use this  ip  in  your  cod

mioo_sara:
if  its  complicated  and  time  consuming  just  answer  my  question  in  first  post  of  this  topic  and  i will  solve  the  other  parts  with  external  aps  automatically
just  replace  first  line  ip  in  post #1 with  old  ip in  5th  line
thanks

Hackoo:
Give a try for this code, and tell me how it works on your side ?

--- Code: ---@echo off
for /f "tokens=1" %%a in ('findstr "192.168.11." mynew-ip.txt') do set IP=%%a
echo The new working IP is %IP%
pause
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version