Can someone make this script

Hello
Please can someone make a script for send credentials to connect a hotspot that do:
1-Ping
2-if ping ok sleep for 10 min
3-if ping failed
Run this command: curl "https://wifi.free.fr" -s -k --data "login=xxxxx&password=xxxxxxxxx&submit=Valider" --connect-timeout 10 --max-time 10 "https://wifi.free.fr/Auth" 2>/dev/null | grep -c "CONNEXION AU SERVICE REUSSIE"
4- start from step 1
Thank you

function go()
{
   if ! ping -c 1 site-to-ping.com 
     then 
  { 
   curl "https://wifi.free.fr" -s -k --data "login=xxxxx&password=xxxxxxxxx&submit=Valider" --connect-timeout 10 --max-time 10 "https://wifi.free.fr/Auth" 2>/dev/null | grep -c "CONNEXION AU SERVICE REUSSIE"
sleep 30
}
else
{
sleep 600;
}
fi
}
while true
do
    go
done
1 Like

thankyou for your help
but it stuck on ping loop

root@LEDE:~# /root/freewifi.sh
PING 208.67.220.220 (208.67.220.220): 56 data bytes
ping: sendto: Network unreachable
0
PING 208.67.220.220 (208.67.220.220): 56 data bytes
ping: sendto: Network unreachable
0
PING 208.67.220.220 (208.67.220.220): 56 data bytes
ping: sendto: Network unreachable
0
<

i want it for this order if possible
1-Ping
1a-if ping ok sleep 10 min
1b- if ping failed run the command for send credencials to the hotspot
2-wait 30s and start from step 1

sorry for my english
regards

added a line in the script .

Sorry but still on ping failed loop
I want to run the command (curl) when ping failed (no network data)
If ping is ok sleep 10 min and recheck

If ping fails you run curl ok ? What after that ? Exit script ?

thankyou
the script run good :+1:
tomorrow i will test if url work because today i have problem with user and password
regards

I was about to reply u , as your case will be served by script after removing the function call from loop

no more ping loop
it's login and password problem tomorrow i receive others and test it better

Rather than pinging the remote client, you can always use your curl to grep for the 200 OK response. Comme ça:

curl -Isk https://wifi.free.fr|grep -Fc 'HTTP/1.1 200 OK'

This returns 1 if it's ok or 0 if not.

The grand problem with ping is it is a security vulnerabilty; a website should never expose ping responses to the world, except maybe when testing.

1 Like

Comme ça?:

function go()
{
   if ! curl -Isk https://wifi.free.fr|grep -Fc 'HTTP/1.1 200 OK'
     then 
  { 
   curl "https://wifi.free.fr" -s -k --data "login=xxxx&password=xxxxxx&submit=Valider" --connect-timeout 25 --max-time 25 "https://wifi.free.fr/Auth" 2>/dev/null | grep -c "CONNEXION AU SERVICE REUSSIE"
}
else
{
sleep 600;
}
fi
}
while true
do
    go
done

Hi
I have tested both
Script with ping work fine maybe is better stop script from runing after ping success and add cron to run it every 10 or 15 minutes only when im on home
Script with with if ! Curl -isk... Don't work. the first curl return 1 always . and the second curl don't run the wifi. free. fr is always accessible its the hotspot access website mybe is the problem. Maybe if you change with other url (ebay. Google...)
Thank you

HI @Abdelhalim38 you can certainly do what @Geekuino is saying

This may gives you a false positive a lot many times you have to be very careful for app changes , More false positive may come if your server is behind HA or Load Balancer as their fault tolerance mechanism involves HTTP redirections . This curl and grep thing will fail then as http response status at that time will be
HTTP/1.1 302 or HTTP/1.1 301 so your grep pattern will miss it and will give 0

54%20PM

more over curl miss to follow redirections originated by java scripts ( @Geekuino ) you can google about it

more over HTTP you can just see the packet length . even if you try to see the http response header length you will realise that ICMP as a whole packet size is much smaller than HTTP header

Again a disagreement with you @Geekuino , I think i can write a whole page on whiich is more Vulnerable protocol :stuck_out_tongue:

1 Like

are you still facing issue or it got resolved ?

1 Like

Thank you very much
Ping and authentication work fine on your script
How can i exit/stop script after ping ok?
I want to do cron jobs every x time to prevent script runing all time
Regards

1 Like

I ll tell u. .. I ll make it a daemon ok ? You can run it like a service then

@arjuniet Thank you for your example on why curl misses the important facts. Using wget is a better method, but OpenWRT needs the wget package with SSL support installing. As for ping, expecting a third party web server to respond to ICMP/pings is bad practice. Web masters are paranoid about ICMP/ping attacks and tend to drop everything!

With regard to the script, I would run it as a cron job, so there is no worrying about processes/privilages. I note @Abdelhalim38's French website expects clients to be using specific hardware.

1 Like

dude thanks for replying in a professional way . This is really missing in this group. no one is really ready to listen to anyone

really i have hardly seen any such case with the well known ISP and websites . But really i agree with you if unreliability is there then we have to opt for alternatives like you give .

as far as i remember ICMP attacks to servers ( excluding broadcast ping ) dont have that much impact on resources as this TCP and SSL handshakes have. you just compare the response and request sizes of ssl handshakes packects

Thanks to @arjuniet and @Geekuino for all your helps
For wget: i have extract the curl command (with some modifications) from other script that use wget.
I have used the other script without success " called YAWAC"
Regards

struck in some discusion , i ll send you what yoi asked me for ...

1 Like