Wifi-SNCF-TGV/wifi-sncf-tgv.sh
2024-08-22 13:02:37 +02:00

24 lines
No EOL
834 B
Bash

#!/usr/bin/env bash
### Wifi @ SNCF TGV INOUI
### Sacha at aquilenet.fr 20240401
### Validate captive portal access
# Put your wifi interface name here
wifiinterface="wlp170s0"
tmpfile=/tmp/wifi-tgv.tmp
# Check if we have nmap
which nmap || echo "Please install nmap" && exit 1
# Get DHCP answears
nmap --script broadcast-dhcp-discover -e $wifiinterface > $tmpfile
DNS=$(grep "Domain Name Server" $tmpfile | awk -F: '{gsub (" ", "", $0); print $2}')
# Enabling the wifi
echo "Enabling SNCF's Wifi"
curl --silent --output /dev/null -X POST 'https://wifi.sncf/router/api/connection/activate/auto' --resolve wifi.sncf:443:$DNS
# Optional: Check if we have Internet (& DNS resolution) with perdu.com
echo -n "Checking Internet Access... "
curl --silent perdu.com |grep ici && echo "Internet is OK !!!" || echo "Internet is KO :((("