From 207c8f22e0eb3c3e2621ebe0d11d8da522d4ef1d Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 15 Jan 2018 04:00:13 +0100 Subject: Init tethapp --- tethapp.sh | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100755 tethapp.sh diff --git a/tethapp.sh b/tethapp.sh new file mode 100755 index 0000000..3d859d8 --- /dev/null +++ b/tethapp.sh @@ -0,0 +1,173 @@ +#!/usr/bin/env bash + +# Ceci est un script bash ayant pour but de créer un partage de connection +# +# + +ssid=🦄 +passphrase=chocolat + +ip=10.5.5.11 +network=10.5.5.0/24 +dhcp_range=$(echo 10.5.5.{12\,,254}),12h + + +function guess_wifi { + for i in `ls /sys/class/net/`; do + if [ -d "/sys/class/net/$i/wireless" ] ; then + _interface="$i" + fi + done + echo "${_interface}" +} +function guess_internet { + echo $(ip route show | grep 'default' | \ + sed 's/.*dev/dev/' | sed 's/scope//' | \ + sed 's/src \([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}//g' | \ + sed 's/link//' | + tr -s ' ' | + cut -d' ' -f 2) +} + + +#net.ipv4.ip_forward=1 +#sudo snnnnet.ipv4.ip_forward=1 +#sudo systnnet.ipv4.ip_forward=1 +#sudo sysctl -w net.ipv4.ip_forward=1 + +echo 'Voici la configuration des interfaces :' +sudo ip a +echo +echo +echo 'Veuillez vérifier la table de routage :' +sudo ip r +echo + + +echo 'Activation de IP fowarding' +sudo sysctl -w net.ipv4.ip_forward=1 + +if [ -z "${1}" ] ; then + echo "Détection automatique de l'interface Wifi" + interface=$(guess_wifi) +else + interface="${1}" +fi + +echo "Interface Wifi : ${interface}" + + +if [ -z "${2}" ] ; then + echo "Détection automatique de l'interface connectée à internet" + interface_internet="$(guess_internet)" +else + interface="${2}" +fi + + +# sudo iw dev wlp3s0 interface add wlan1 type station +sudo pkill dnsmasq + + +echo "Configuration de l'IP 10.5.5.11" +sudo ifconfig "${interface}" up 10.5.5.11 netmask 255.255.255.0 + +echo "Configuration de DNSQMASQ" + +cat <<< $( +echo " + interface=${interface} + listen-address=${ip} + bind-interfaces + dhcp-range=${dhcp_range}" +) > /tmp/dnsmasq.conf + + + +echo 'Lancement de DNSMASQ (DHCP sur le réseau 10.5.5.0/24)' +sudo dnsmasq --conf-file=/tmp/dnsmasq.conf + +echo "Activation de l'interface ${interface}" +sudo ip link set "${interface}" up + +echo 'Ajout du réseau dans la table de routage' +sudo ip r add 10.5.5.0/24 via 10.5.5.11 dev "${interface}" + + +echo "Routage des connections internet" +sudo iptables -t nat -A POSTROUTING -o "${interface_internet}" -j MASQUERADE +sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT +sudo iptables -A FORWARD -i "${interface}" -o "${interface_internet}" -j ACCEPT + + + +echo "Configuration de hostapd" + +cat <<< $( +echo " +interface=${interface} +ssid=${ssid} + +wpa=1 +wpa_passphrase=${passphrase} + +channel=1 +hw_mode=g + +logger_syslog=-1 +logger_syslog_level=2 +logger_stdout=-1 +logger_stdout_level=2 + +ctrl_interface=/var/run/hostapd +ctrl_interface_group=0 + +beacon_int=100 +dtim_period=2 +max_num_sta=255 +rts_threshold=2347 +fragm_threshold=2346 +macaddr_acl=0 +auth_algs=3 +ignore_broadcast_ssid=0 + +wmm_enabled=1 +wmm_ac_bk_cwmin=4 +wmm_ac_bk_cwmax=10 +wmm_ac_bk_aifs=7 +wmm_ac_bk_txop_limit=0 +wmm_ac_bk_acm=0 +wmm_ac_be_aifs=3 +wmm_ac_be_cwmin=4 +wmm_ac_be_cwmax=10 +wmm_ac_be_txop_limit=0 +wmm_ac_be_acm=0 +wmm_ac_vi_aifs=2 +wmm_ac_vi_cwmin=3 +wmm_ac_vi_cwmax=4 +wmm_ac_vi_txop_limit=94 +wmm_ac_vi_acm=0 +wmm_ac_vo_aifs=2 +wmm_ac_vo_cwmin=2 +wmm_ac_vo_cwmax=3 +wmm_ac_vo_txop_limit=47 +wmm_ac_vo_acm=0 + +vht_oper_chwidth=3 +eap_message=hello +eapol_key_index_workaround=0 +eap_server=0" +) > /tmp/hostapd.conf + + + +echo "Lancement du hostpot Wifi" +sudo hostapd /tmp/hostapd.conf + +echo 'Clean des iptables' +sudo iptables --flush +sudo iptables -t nat --flush + +echo 'Bye 💋' +echo 'Have a nice day <3' + -- cgit v1.2.3