Can someone make this script


#1

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


#2
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

Securing OpenWrt Setups ( recomendations )
#3

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


#4

added a line in the script .


#5

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


#6

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


#7

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


#8

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


#9

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


#10

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.


#11

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

#12

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


#13

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

55%20PM

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:


#14

are you still facing issue or it got resolved ?


#15

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


#16

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


#17

@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.


#18

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


#19

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


#20

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