Partager sa connexion 4G on linux

Le savoir est une arme


Souvent en déplacement, utilisateur d’une debian, il n’est pas souvent simple de partager sa connexion 4G.
C’est pourquoi j’ai décidé de vous partager, un simple script, permettant à tout système Linux de pouvoir partager sa connexion 4G.


Configuration

Copier/Coller simplement ce bout de script et donné lui les droits d’executions.

#!/bin/bash
#set -xe 
## Script for initialize the data connexion with USB DHCLIENT
## Pre requis : Connect your smartphone in USB
## Define your variables 
USB=usb0
export USB

Green='\e[0;32m'
Red='\e[0;31m'
Nocolor='\e[0m' # for no color the rest

## functions for know your provided phone
echo "########################"
echo "for example Samsung, Iphone, Asus"
echo -n "Please enter the modele as your phone : "
read phone
echo "Your model phone is : $phone"
echo "########################"

## functions find your Phone in lsusb
FIND_PHONE=`lsusb | grep $phone | wc -l`
export FIND_PHONE

echo "#########################"
echo "Testing where is your USB"
if [ $FIND_PHONE -eq 1 ] ; then
	echo "We have find your phone"
	echo "#######################"
else	
	echo "We don't have find your phone"
	echo "#############################"
	exit 1
fi
## function for testing if your configuration is already exist in ifconfig
FIND_USB0=`sudo ifconfig | grep $USB | wc -l`
export FIND_USB0

if [ "$FIND_USB0" -eq 1 ]; then
        echo "##########################"
        echo "Your device is already configurate"
        exit 0
fi

## functions validate your case on share connecting 3G on Phone and activate dhclient from usb0 
echo "#############################"
echo "Are you sure if your phone is activate for shared the data connection ?" 
echo -e "Please confirm your case by ${Green}Y${Nocolor}/${Red}n${Nocolor} : " 
read active 

if [ "$active" == "Y" ] ; then
	echo "Wait minutes please before configuration"
	sudo dhclient $USB
	echo "Your device is configurate for using data sharing connection"
	sudo ifconfig
	echo "########################################"   
else	
	echo "Please plug your phone for activate the shared data connection"
	echo "########################################"
	exit 1  
fi
## functions for testing resolving google
PING=`sleep 3s | ping google.fr | echo $?`
export PING
if [ $PING -eq 0 ]; then
	echo -e "Testing if your resolved is OK : [${Green}OK${Nocolor}]"
else 
	echo -e "Testing if your resolved is KO : [${Red}KO${Nocolor}]"
fi	
## functions for return status command dhclient 
status=$?
if [ $status -ne 0 ]; then 
	echo "##########################"
	echo "You have one error with $?"
	echo "echo $?"  
	echo "##########################"
fi
exit $?

Rendre le script executable :

chmod +x script.sh

Utilisation

Simple d’utilisation, il vous suffit de l’executer, saisir le modèle de votre téléphone et vous assurez d’avoir partagé votre connexion 4G/3G via USB.

########################
for example Samsung, Iphone, Asus
Please enter the model : Galaxy
Your model phone is : Galaxy
########################
#########################
Testing where is your USB
We have find your phone
#######################
[sudo] Mot de passe de User : 
#############################
Do you've share the data connection ?
Please confirm your case by Y/n : 
Y
Wait minutes please before configuration
Cannot find device "usb0"
Your device is configurate for using data sharing connection
enp0s29u1u3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.42.132  netmask 255.255.255.0  broadcast 192.168.42.255
        inet6 2a04:cec0:1005:9cbf:fdf4:fb:cc54:ee11  prefixlen 64  scopeid 0x0<global>
        inet6 2a04:cec0:1005:9cbf:14f4:dff:fe42:3378  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::14f4:dff:fe42:3378  prefixlen 64  scopeid 0x20<link>
        ether 16:f4:0d:42:33:78  txqueuelen 1000  (Ethernet)
        RX packets 20490  bytes 15659946 (14.9 MiB)
        RX errors 3  dropped 0  overruns 0  frame 3
        TX packets 16794  bytes 3437175 (3.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp10s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether d0:67:e5:2e:ea:53  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 18  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Boucle locale)
        RX packets 3218  bytes 260332 (254.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3218  bytes 260332 (254.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

########################################
Testing if your resolved is OK : [OK]

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *