1.shell script gets the native IP address:
localhostip= ' lc_all=c ifconfig 'inet addr:'127.0.0.1' | '{print $}'"$localhostIP"
2. Automate the setup of an IPSec test environment:
#!/bin/Bash#sudo Suecho"Get root! "apt-get Install Strongswan- y//required to press Y during installation, so after adding the-y parameter, you will automatically agree to install the localhostip= ' Lc_all=c ifconfig | Grep'inet Addr:'| Grep-v'127.0.0.1'|Cut-D:-f2 | Awk'{print $}'' echo"$localhostIP"ls/etc/ipsec.*CD/etcpwdifTest-e./Ipsec.confthen Echo"exit ipsec.conf start Write something!"Echo"Conn Ipsec_serverKeyexchange=IKEV1 Type=Tunnel Left=$localhostIP Right=%Any ESP=des-md5-modp768 Ike=des-md5-modp768 Auto=Start Authby=psk">> ipsec.confElseEcho"ipsec.conf No Exit!!!"fiifTest-e./Ipsec.secretsthen Echo"exit ipsec.secrets start Write something!"Echo": PSK ' 123456 '">>ipsec.secretsElseEcho"ipsec.secrets No Exit!!!"Fiecho"-----OK-----------"IPSec Restart
3. Running Result: note To run the script as root
Shell Combat: Script Automation to build an IPSec test environment