-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi2ether_share
119 lines (95 loc) · 2.91 KB
/
wifi2ether_share
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
clear
echo "Instalando dependencias..."
apt-get install dnsmasq iptables -y
echo " ";
#Selecionando interfaz wifi
echo "Tarjetas wifi disponibles"
#iwconfig 2>/dev/null |grep IEEE |awk '{print $1}'
iwconfig 2>/dev/null |grep IEEE |awk '{ print "\033[1m"$1"\033[0m"}'
echo " ";
echo "Introduzca el nobre de la tarjeta que se conectara a internet (ej: wlan0) :";
echo " ";
read WIFICARD
echo "Tarjeta selecionada : $WIFICARD";
echo " ";
#Selecionando interfaz ethernet
echo "Tarjetas ethernet disponibles"
#iwconfig 2>&1 >/dev/null | grep "no wireless extensions" |awk '{print $1}'
#iwconfig 2>&1 | grep "no wireless extensions" |awk '{print $1}'
iwconfig 2>&1 | grep "no wireless extensions"|awk '{ print "\033[1m"$1"\033[0m"}'
echo " ";
echo "Introduzca el nobre de la tarjeta ethernet que ofrecerá internet (ej: eth0) :";
echo " ";
read ETHCARD
echo "Tarjeta selecionada : $ETHCARD";
echo " ";
#Selecionando red wifi
echo "Redes WIFI detectadas: "
iwlist $WIFICARD scan |grep ESSID
echo " ";
echo "Introduzca el nobre de la red (ej: WLAN_XXXX) :";
echo " ";
read WIFIESSID
echo "Red selecionada : $WIFIESSID";
echo " ";
echo "Introduzca la contraseña de la red wifi :";
echo " ";
read WIFIPASS
echo " ";
####### Generando archivo interfaces ##########
echo "Prearando interfaces..."
rm interfaces 2>/dev/null
echo "#source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto $ETHCARD
iface $ETHCARD inet static
address 192.168.0.1
netmask 255.255.255.0
broadcast 192.168.0.255
auto $WIFICARD
iface $WIFICARD inet dhcp
pre-up sudo iwconfig $WIFICARD power on
wpa-ssid $WIFIESSID
wpa-psk $WIFIPASS
post-up sudo share $WIFICARD $ETHCARD
" > interfaces
####### Generando archivo share ##########
echo "Prearando NAT..."
rm share 2>/dev/null
echo '#!/bin/bash
sudo iptables -t nat -A POSTROUTING -o "$1" -j MASQUERADE
sudo iptables -A FORWARD -i "$1" -o "$2" -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i "$2" -o "$1" -j ACCEPT' > share
cp share /usr/bin/share
chmod +x /usr/bin/share
#################################################
if [ -e /etc/router ]
then
#nada que hacer
echo ""
else
cp /etc/network/interfaces /etc/network/interfaces.bak
echo 1 > /proc/sys/net/ipv4/ip_forward
echo "Configurando net.ipv4.ip_forward=1 en /etc/sysctl.conf ..."
echo " " >> /etc/sysctl.conf
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl --system
echo "Configurando servidor dhcp..."
echo " " >> /etc/dnsmasq.conf
echo "listen-address=192.168.0.1" >> /etc/dnsmasq.conf
echo "bind-interfaces" >> /etc/dnsmasq.conf
echo "dhcp-range=192.168.0.2,192.168.0.254,12h" >> /etc/dnsmasq.conf
echo 1 > /etc/router
fi
echo "Configurando interfaces..."
cp interfaces /etc/network/interfaces
echo "Reiniciando tarjetas de red..."
ifdown -a -vv
ifup -a -vv
echo "Reiniciando dnsmasq..."
/etc/init.d/dnsmasq restart
echo " ";
echo "FINALIZADO"
exit 0