Usuku oluhle!
Kulesi sihloko ngifuna ukukutshela ukuthi ngenze kanjani (
Ukusungula uxhumano kuhlanganisa izinyathelo ezimbalwa:
- Ukuqala i-node futhi ulinde ukuthi i-node ekude ilungele;
- Ukunquma ikheli le-IP langaphandle kanye nechweba le-UDP;
- Ukudlulisa ikheli le-IP langaphandle kanye nembobo ye-UDP kumsingathi oqhelile;
- Ukuthola ikheli le-IP langaphandle kanye nembobo ye-UDP kumsingathi oqhelile;
- Inhlangano yomhubhe we-IPIP;
- Ukuqapha ukuxhumana;
- Uma uxhumano lulahlekile, susa umhubhe we-IPIP.
Ngacabanga isikhathi eside futhi ngisacabanga ukuthi yini engasetshenziswa ukushintshanisa idatha phakathi kwama-node, elula futhi esheshayo kimi okwamanje isebenza nge-Yandex.disk.
- Okokuqala, kulula ukuyisebenzisa - udinga izenzo ezi-3: dala, funda, susa. Nge-curl lokhu:
Dala:curl -s -X MKCOL --user "$usename:$password" https://webdav.yandex.ru/$folder
Funda:
curl -s --user "$usename:$password" -X PROPFIND -H "Depth: 1" https://webdav.yandex.ru/$folder
Susa:
curl -s -X DELETE --user "$usename:$password" https://webdav.yandex.ru/$folder
- Okwesibili, kulula ukuyifaka:
apt install curl
Ukuze unqume ikheli le-IP langaphandle kanye nembobo ye-UDP, sebenzisa umyalo we-stun-client:
stun stun.sipnet.ru -v -p $1 2>&1 | grep "MappedAddress"
Ukufakwa ngomyalo:
apt install stun-client
Ukuze uhlele umhubhe, amathuluzi ajwayelekile we-OS asuka kuphakheji ye-iproute2 asetshenziswa. Ikhona
- layisha imojula ye-FOU:
modprobe fou
- lalela imbobo yendawo:
ip fou add port $localport ipproto 4
- dala umhubhe:
ip link add name fou$name type ipip remote $remoteip local $localip encap fou encap-sport $localport encap-dport $remoteport
- phakamisa isixhumi esibonakalayo somhubhe:
ip link set up dev fou$name
- nika amakheli e-IP angaphakathi nangaphakathi akude emhubheni:
ip addr add $intIP peer $peerip dev fou$name
Susa umhubhe:
ip link del dev fou$name
ip fou del port $localport
Isimo somhubhe sigadwa ngokukhala ngezikhathi ezithile ikheli le-IP langaphakathi lomhubhe we-node ekude ngomyalo:
ping -c 1 $peerip -s 0
I-ping yezikhathi ezithile iyadingeka ngokuyinhloko ukuze kugcinwe isiteshi, ngaphandle kwalokho, lapho umhubhe ungenzi lutho, amatafula e-NAT kumarutha angase asulwe bese uxhumano luzophuka.
Uma i-ping inyamalala, khona-ke umhubhe we-IPIP uyasuswa futhi ulinde ukulungela kumsingathi oqhelile.
Iskripthi ngokwaso:
#!/bin/bash
username="[email protected]"
password="password"
folder="vpnid"
intip="10.0.0.1"
localport=`shuf -i 10000-65000 -n 1`
cid=`shuf -i 10000-99999 -n 1`
tid=`shuf -i 10-99 -n 1`
function yaread {
curl -s --user "$1:$2" -X PROPFIND -H "Depth: 1" https://webdav.yandex.ru/$3 | sed 's/></>n</g' | grep "displayname" | sed 's/<d:displayname>//g' | sed 's/</d:displayname>//g' | grep -v $3 | grep -v $4 | sort -r
}
function yacreate {
curl -s -X MKCOL --user "$1:$2" https://webdav.yandex.ru/$3
}
function yadelete {
curl -s -X DELETE --user "$1:$2" https://webdav.yandex.ru/$3
}
function myipport {
stun stun.sipnet.ru -v -p $1 2>&1 | grep "MappedAddress" | sort | uniq | awk '{print $3}' | head -n1
}
function tunnel-up {
modprobe fou
ip fou add port $4 ipproto 4
ip link add name fou$7 type ipip remote $1 local $3 encap fou encap-sport $4 encap-dport $2
ip link set up dev fou$7
ip addr add $6 peer $5 dev fou$7
}
function tunnel-check {
sleep 10
pings=0
until [[ $pings == 4 ]]; do
if ping -c 1 $1 -s 0 &>/dev/null;
then echo -n .; n=0
else echo -n !; ((pings++))
fi
sleep 15
done
}
function tunnel-down {
ip link del dev fou$1
ip fou del port $2
}
trap 'echo -e "nDisconnecting..." && yadelete $username $password $folder; tunnel-down $tunnelid $localport; echo "IPIP tunnel disconnected!"; exit 1' 1 2 3 8 9 14 15
until [[ -n $end ]]; do
yacreate $username $password $folder
until [[ -n $ip ]]; do
mydate=`date +%s`
timeout="60"
list=`yaread $username $password $folder $cid | head -n1`
yacreate $username $password $folder/$mydate:$cid
for l in $list; do
if [ `echo $l | sed 's/:/ /g' | awk {'print $1'}` -ge $(($mydate-65)) ]; then
#echo $list
myipport=`myipport $localport`
yacreate $username $password $folder/$mydate:$cid:$myipport:$intip:$tid
timeout=$(( $timeout + `echo $l | sed 's/:/ /g' | awk {'print $1'}` - $mydate + 3 ))
ip=`echo $l | sed 's/:/ /g' | awk '{print $3}'`
port=`echo $l | sed 's/:/ /g' | awk '{print $4}'`
peerip=`echo $l | sed 's/:/ /g' | awk '{print $5}'`
peerid=`echo $l | sed 's/:/ /g' | awk '{print $6}'`
if [[ -n $peerid ]]; then tunnelid=$(($peerid*$tid)); fi
fi
done
if ( [[ -z "$ip" ]] && [ "$timeout" -gt 0 ] ) ; then
echo -n "!"
sleep $timeout
fi
done
localip=`ip route get $ip | head -n1 | sed 's|.*src ||' | cut -d' ' -f1`
tunnel-up $ip $port $localip $localport $peerip $intip $tunnelid
tunnel-check $peerip
tunnel-down $tunnelid $localport
yadelete $username $password $folder
unset ip port myipport
done
exit 0
Okuguquguqukayo igama lomsebenzisi, iphasiwedi ΠΈ ifolda kufanele kufane nhlangothi zombili, kodwa ithiphu - ezahlukene, isibonelo: 10.0.0.1 futhi 10.0.0.2. Isikhathi kuma-node kumele sivunyelaniswe. Ungaqalisa iskripthi kanje:
nohup script.sh &
Ngithanda ukunakwa ukuthi umhubhe we-IPIP awuphephile ngokombono wokuthi ithrafikhi ayibethelwanga, kepha lokhu kungaxazululwa kalula kusetshenziswa i-IPsec ngaphezulu.
Bengisebenzisa lesi sikripthi ukuxhuma ku-PC yomsebenzi amasonto ambalwa manje futhi angizange ngiqaphele izinkinga. Elula mayelana nokuyibeka futhi uyikhohlwe.
Mhlawumbe uzoba nokuphawula nokusikisela, ngizokujabulela ukulalela.
Π‘ΠΏΠ°ΡΠΈΠ±ΠΎ Π·Π° Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅!
Source: www.habr.com