The problem lies in 2 things:
When you use the IP variable you are not using it as such, but that variable according to your code represents the last number of an IP, I mean these lines:
ping -n 1 10.10.222."%IP%" | find "Respuesta" > a1.txt
ping -n 1 10.10.222."%IP%" | find "Tiempo de espera agotado" > a2.txt
Here you would have two options:
Change the name of your variable and what you ask the user with, for example, the lastNumeroIp
ping -n 1 10.10.222."%ultimoNumeroIp%" | find "Respuesta" > a1.txt
ping -n 1 10.10.222."%ultimoNumeroIp%" | find "Tiempo de espera agotado" > a2.txt
Or you remove the numbers to these two lines and you really use the IP variable in such a way that it would look like this:
ping -n 1 "%IP%" | find "Respuesta" > a1.txt
ping -n 1 "%IP%" | find "Tiempo de espera agotado" > a2.txt
and the other problem I see is the use of the variables % a1% and % a2% when they should be % p1% and % p2% according to the definition you've made in the lines:
set /p p1=< a1.txt
set /p p2=< a2.txt
Summing up the code of your script would look like this:
@echo off
:bucle
set a1=.
set a2=.
set /p IP=Escribe la IP a la que quieres hacer Ping:
ping -n 1 %IP% | find "Respuesta" > a1.txt
ping -n 1 %IP% | find "Tiempo de espera agotado" > a2.txt
set /p p1=< a1.txt
set /p p2=< a2.txt
echo %date% %time% %p1% %p2%
echo %date% %time% %p1% %p2% >> log.txt
break > a1.txt
break > a2.txt
ping 127.0.0.1 -w 1000 -n 2 > NUL
GOTO bucle
NOTE: what you thought was the last line was not, but was the result of
echo %date% %time% %a1% %a2%
that as % a1%% a2% they had nothing written to you the date and time
Greetings and I hope I have helped you