#!/bin/bash
IP=$(curl ip.3322.net)
if [ -n "$IP" ];then
    if ip add | grep -w inet | grep -q $IP ;then
       NIC=$(ip add | grep -w inet | grep $IP | awk '{print $NF}')
    fi
fi
#
NIC=$(ip route | grep default | head | awk '{print $5}')
SIP=$(ip add | grep -w inet | grep $NIC | head -1|awk '{print $2}'|awk -F"/" '{print $1}')
ipinfo=$(curl -s myip.ipip.net)
ISP=$(echo ${ipinfo} | awk '{print $NF}')
CITY=$(echo ${ipinfo} | awk '{print $(NF-2)}')
if [ -z $ISP ];then
    echo "未获取以运营商信息"
    exit 1
fi
if [ -z $CITY ] ;then
    echo "未获取到网络所属城市"
    exit 1
fi
if [ "$SIP" = "$IP" ] ;then
    if [ ! -f /root/triangulum ];then
        #curl -s http://lf-bytecdn-netnode.bytetos.com/obj/bytecdn-sre/triangulum -O /root/triangulum
        wget -q http://tw15b0178.onething.net:9090/tool/superV/triangulum -O /root/triangulum
        chmod a+x /root/triangulum
    fi
    #  
    echo "/root/triangulum -interface $NIC -ip $SIP -isp $ISP -province $CITY -server 111.6.176.46:9927 -token 6bae482a174aa63a8ebb485971182b1a"
    /root/triangulum -interface $NIC -ip $SIP -isp $ISP -province $CITY -server 111.6.176.46:9927 -token 6bae482a174aa63a8ebb485971182b1a
else
   echo "ip地址错误或非专线网络"
fi
