!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache. PHP/7.3.33 

uname -a: Linux acloudg.aryanict.com 4.18.0-513.9.1.lve.el8.x86_64 #1 SMP Mon Dec 4 15:01:22 UTC
2023 x86_64
 

uid=1095(katebhospital) gid=1098(katebhospital) groups=1098(katebhospital) 

Safe-mode: OFF (not secure)

/opt/scripts/hv/   drwxr-xr-x
Free 293.65 GB of 429.69 GB (68.34%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     networking.sh (23.7 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/bin/bash

function select_nics () {
    #manually select nics
    PS3="Select 2 NICs:"
    select nic in ${nics[@]}
    do
        new_nics+=("$nic")
        len=${#new_nics[@]}
        if [[ len -eq 2 ]];then
            break
        fi
    done
    nic_reselect="yes"
    get_nics
}


function select_ip () {
    #manually select ip
    PS3="Select 1 IP:"
    select ip in ${ip_array[@]}
    do
        ip_array=("$ip")
        break
    done
    ip_reselect="yes"
    get_ips
}


function get_nics() {
    #try to automatically select nics,
    #if the automatic selection doesnt equal 2,
    #it will send you to an interactive prompt to select them,
    #unless youve launched with the unattended argument

    #clear any existing nic variable
    unset nics
    #if unattended mode requested
    if [[ "$unattended" == "y" ]];then
        if [[ -f /opt/scripts/ips.txt ]];then
            public_mac=$(cat /opt/scripts/ips.txt |grep mac_1 | awk '{print $2}')
            private_mac=$(cat /opt/scripts/ips.txt |grep mac_0 | awk '{print $2}')
            if [[ -f /proc/net/bonding/bond0 ]];then
                public_nic=$(cat /proc/net/bonding/bond0 | grep $public_mac -b5 |grep -i "Slave Interface" |cut -f2 -d ":")
                private_nic=$(cat /proc/net/bonding/bond0 | grep $private_mac -b5 |grep -i "Slave Interface" |cut -f2 -d ":")
            else
                public_nic=$(ip -o link | grep $public_mac | awk '{print $2}' | cut -f1 -d":")
                private_nic=$(ip -o link | grep $private_mac | awk '{print $2}' | cut -f1 -d":")
            fi
            nics=("$public_nic" "$private_nic")
        else
            #check for up interfaces
            up_interfaces=($(ip link show up | grep -v lo|grep -v link | awk '{print $2}' | cut -f1 -d":" | grep -v bond))
            len=${#up_interfaces[@]}
            #make sure we only found 2 interfaces
            if [[ ! len -eq 2 ]];then
                for nic in ${up_interfaces[@]};do
                    #if we find 10., its private
                    if [[ `ip a show dev $nic | grep 'inet 10.'1` ]];then
                        private_nic=$nic
                    #if we find something other than 10. its public
                    elif [[ `ip a show dev $nic | grep inet | grep -v 'inet 10.'` ]];then
                        public_nic=$nic
                    fi
                done
                #if there is no private nic found
                if [[ -z $private_nic ]];then
                    #but the public nic is found
                    if [[ ! -z $public_nic ]];then
                        for nic in ${up_interfaces[@]};do
                            #if nic is not the public interface
                            if [[ $nic -eq "$public_nic" ]];then
                                private_nic=$nic
                            fi
                        done
                    fi
                fi
                #if there is no public nic found
                if [[ -z $public_nic ]];then
                    #but the private nic is found
                    if [[ ! -z $private_nic ]];then
                        for nic in ${up_interfaces[@]};do
                            #if nic is not the private interface
                            if [[ $nic -eq "$private_nic" ]];then
                                private_nic=$nic
                            fi
                        done
                    fi
                fi
                #at this point it should have both, if not, exit failed
                if [[ -z $public_nic ]];then
                    echo "could not determine the 2 nics to use, guessing"
                    nics=($(ip link |grep state |  awk '{print $2}' | grep -v 'lo\|bond\|vmbr' | cut -f 1 -d':' ))
                    public_nic=${nics[0]}
                fi
                if [[ -z $private_nic ]];then
                    echo "could not determine the 2 nics to use, guessing"
                    nics=($(ip link |grep state |  awk '{print $2}' | grep -v 'lo\|bond\|vmbr' | cut -f 1 -d':' ))
                    private_nic=${nics[1]}
                fi
                #if everything is good, create the nics array and move forward
                nics=("$public_nic" "$private_nic")
            #if quantity of nics is 2
            elif [[ len -eq 2 ]];then
                for nic in ${up_interfaces[@]};do
                    echo $nic
                    #build nics array and move on
                    nics+=("$nic")
                done
            fi
            echo ${nics[*]}
            len=${#nics[@]}
            if [[ ! len -eq 2 ]];then
                echo "failed to get 2 nics"
                exit 1
            fi
        fi
    #if you selected more or less than 2 nics, or this is the first try, attempt to get 2 nics
    elif [[ "$nic_reselect" != "yes" ]];then
        unset nic_reselect
        nics=($(ip link |grep state |  awk '{print $2}' | grep -v 'lo\|bond\|vmbr' | cut -f 1 -d':' ))
        #ignore default bridge if this is proxmox
        if [[ -f "/etc/apt/sources.list.d/pve-enterprise.list" ]];then
            delete="vmbr0"
            nics=("${nics[@]/$delete}")
        fi
    #if you selected 2 nics in select_nics function, proceed.
    else
        nics=(${new_nics[@]})
    fi
    len=${#nics[@]}
    if [[ "$len" -gt 2 ]];then
        echo 'more than 2 nics, please select the nics to use. ex. [1] [Enter] [2] [Enter]:'
        select_nics
    elif [[ "$len" -lt 2 ]];then
        echo 'less than 2 nics available, please investigate'
        exit 1
    else
        nic1=${nics[0]}
        nic2=${nics[-1]}
    fi
}


function try_to_pull_ip_from_config () {
    if [[ -f /opt/scripts/ips.txt ]];then
        ip=$(cat /opt/scripts/ips.txt | grep ip_1 | awk '{print $2}')
        netmask=$(cat /opt/scripts/ips.txt | grep mask_1 | awk '{print $2}')
        gateway=$(cat /opt/scripts/ips.txt | grep gateway_1 | awk '{print $2}')
        ipwprefix=$(cat /opt/scripts/ips.txt | grep ip_w_cidr_1 | awk '{print $2}')
        prefix=$(cat /opt/scripts/ips.txt | grep ip_w_cidr_1 | awk '{print $2}'| cut -f2 -d"/")
        mac=$(cat /opt/scripts/ips.txt | grep mac_1 | awk '{print $2}')
    elif [[ -f /etc/netplan/01-netcfg.yaml ]];then 
        ipwprefix=$(cat /etc/netplan/01-netcfg.yaml|grep addresses | cut -f2 -d":" | awk '{print $2}' | head -n1 | sed 's/[][]//g')
        if [[ -z $ipwprefix ]];then
            ipwprefix=$(cat /etc/netplan/01-netcfg.yaml|grep addresses | cut -f2 -d":" | awk '{print $1}'| head -n1 | sed 's/[][]//g')
            if [[ -z $ipwprefix ]];then
                ipwprefix=$(cat /etc/netplan/01-netcfg.yaml|grep -a1 addresses | cut -f2 -d":" | awk '{print $2}'| grep -v 127.0.0.1 | grep -v 10.0.55)
            fi
        fi
        ip=$(echo $ipwprefix | cut -f1 -d'/')
        prefix=$(echo $ipwprefix | cut -f2 -d'/')
        calculate_gateway_mask
    elif [[ -f /etc/network/interfaces ]];then
        ip=$(cat /etc/network/interfaces | grep IPADDR | cut -f2 -d "=")
        prefix=$(cat /etc/network/interfaces | grep PREFIX | cut -f2 -d "=")
        gateway=$(cat /etc/network/interfaces | grep GATEWAY | cut -f2 -d "=" |grep -v 'inet6\|inet 127.\|inet 10.0.55\|192.168.\|10.1[0-9][0-9]')
    fi
}


function get_ips () {
    #try to automatically select ips
    if [[ "$ip_reselect" != "yes" ]];then
        unset ip_reselect
        ip_array=($(ip a show | grep inet | grep -v 'inet6\|inet 127.\|inet 10.0.55\|inet 192.168.\|inet 10.[0-5][0-9]' |awk '{print $2}'))
    fi
    len=${#ip_array[@]}
    if [[ -f /opt/scripts/ips.txt ]];then
        ip=$(cat /opt/scripts/ips.txt | grep ip_1 | awk '{print $2}')
        netmask=$(cat /opt/scripts/ips.txt | grep mask_1 | awk '{print $2}')
        gateway=$(cat /opt/scripts/ips.txt | grep gateway_1 | awk '{print $2}')
        ipwprefix=$(cat /opt/scripts/ips.txt | grep ip_w_cidr_1 | awk '{print $2}')
        prefix=$(cat /opt/scripts/ips.txt | grep ip_w_cidr_1 | awk '{print $2}'| cut -f2 -d"/")
        mac=$(cat /opt/scripts/ips.txt | grep mac_1 | awk '{print $2}')
    elif [[ "$len" -gt 1 ]];then
        if [[ "$unattended" == "y" ]];then
            echo "found too many ips, please run manually"
            exit 1
        else
            echo 'more than 1 ip configured, please select the ip to use'
            select_ip
        fi
    elif [[ "$len" -lt 1 ]];then
        try_to_pull_ip_from_config
        if [[ ! "$ip" =~ ^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$ ]]; then
            if [[ "$unattended" == "y" ]];then
                echo "unable to find a valid ip, please run manually"
                exit 1
            else
                configure_ip
            fi
        fi
    else
        ip=$(echo ${ip_array[0]} | cut -f1 -d'/')
        prefix=$(echo ${ip_array[0]} | cut -f2 -d'/')
        gateway=$(ip ro | grep default | awk '{print $3}'|grep -v 'inet6\|inet 127.\|inet 10.0.55\|192.168.\|10.1[0-9][0-9]')
    fi
    echo $ip/$prefix
    echo $gateway
}


function configure_ip () {
    while true;do
        read -p "Please enter IP address with CIDR. eg. 10.0.0.20/24: " ipwprefix        
        ip=$(echo $ipwprefix | cut -f1 -d"/")
        prefix=$(echo $ipwprefix | cut -f2 -d"/")
        if [[ "$ip" =~ ^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$ ]]; then
            if [[ "$prefix" =~ ^((2[4-9]|3[0-2])) ]];then
                prefix_to_netmask
                calculate_gateway_mask
                read -e -p "Please enter gateway address: " -i "$gateway" gateway
                echo "IP: $ip"
                echo "Netmask:  $netmask"
                echo "Gateway: $gateway"
                read -p "Apply? (y/n): " answer
                ip_set="true"
                if [[ `echo $answer` == "y" ]];then
                    read -p "Enable bonding? (y/n)" answer
                    if [[ $answer == "y" ]];then
                        bond_enable="y"
                        break
                    else
                        bond_disable="y"
                        break
                    fi                    
                fi
            else
                echo "Invalid CIDR/Prefix,  Please try again."
            fi
        else
            echo "Invalid IP, please try again."
        fi
    done
    run_configure
}


function apply_ip () {
    determine_distro
    case $distro in
        centos) centos ;;
        alma  ) alma   ;;
        rocky ) rocky  ;;
        ubuntu) ubuntu ;;
        debian) debian ;;
        *     ) echo "This OS is currently unsupported or unrecognized."
    esac
}


function centos_enable_bond () {
    for nic in "${nics[@]}"
    do
        uuid=$(nmcli connection show $nic |grep connection.uuid | awk '{print $2}')
        hwaddr=$(cat /sys/class/net/$nic/address)
cat <<-EOF > /etc/sysconfig/network-scripts/ifcfg-${nic}
HWADDR="$hwaddr"
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="$nic"
UUID="$uuid"
ONBOOT="yes"
MASTER=bond0
SLAVE=yes
EOF
done

cat <<-EOF > /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
NAME=bond0
TYPE=Bond
BONDING_MASTER=yes
IPADDR=$ip
PREFIX=$prefix
GATEWAY=$gateway
ONBOOT=yes
BOOTPROTO=none
BONDING_OPTS="mode=4 miimon=100 lacp_rate=1"
EOF
    modprobe bonding
}


function centos_disable_bond () {
    rm -rf /etc/sysconfig/network-scripts/ifcfg-bond0
    primary_nic="${nics[0]}"
    secondary_nic="${nics[-1]}"
    primary_uuid=$(nmcli connection show $primary_nic |grep connection.uuid | awk '{print $2}')
    primary_hwaddr=$(cat /sys/class/net/$primary_nic/address)
    secondary_uuid=$(nmcli connection show $secondary_nic |grep connection.uuid | awk '{print $2}')
    secondary_hwaddr=$(cat /sys/class/net/$secondary_nic/address)
cat <<-EOF > /etc/sysconfig/network-scripts/ifcfg-${primary_nic}
NAME=$primary_nic
HWADDR=$primary_hwaddr
ONBOOT=yes
NETBOOT=yes
UUID=$primary_uuid
IPV6INIT=yes
BOOTPROTO=static
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
IPADDR=$ip
PREFIX=$prefix
GATEWAY=$gateway
DNS1=66.96.80.43
DNS2=66.96.80.194
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
DEVICE=$primary_nic
EOF

cat <<-EOF > /etc/sysconfig/network-scripts/ifcfg-${secondary_nic}
TYPE=Ethernet
HWADDR=$secondary_hwaddr
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=$secondary_nic
UUID=$secondary_uuid
DEVICE=$secondary_nic
ONBOOT=no
EOF
}


function netplan_enable () {
    rm -rf /etc/netplan/*
    #setup bonds in netplan
    sudo cat <<-EOFnetplan > /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).

network:
  version: 2
  renderer: networkd
  ethernets:
    $nic1:
      dhcp4: no
      dhcp6: no
    $nic2:
      dhcp4: no
      dhcp6: no

  bonds:
    bond0: 
      interfaces: [$nic1, $nic2]
      addresses: [$ip/$prefix]
      nameservers:
        addresses: [66.96.80.43, 66.96.80.194]
      gateway4: $gateway
      parameters:
        mode: 802.3ad
        lacp-rate: fast
        mii-monitor-interval: 100
        transmit-hash-policy: layer3+4
EOFnetplan
    ip addr flush dev $nic1
    ip addr flush dev $nic2
    netplan apply
    systemctl restart networking
}

function netplan_disable () {
    rm -rf /etc/netplan/*
    cat <<EOFnetplan > /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    $nic1:
      dhcp4: no
      dhcp6: no
      addresses: [$ip/$prefix]
      gateway4: $gateway
      nameservers:
        addresses: [66.96.80.43,66.96.80.194]
EOFnetplan
    netplan apply
    ip link delete dev bond0
    ip addr flush dev $nic1
    ip addr flush dev $nic2
    ip link set $nic1 up
    netplan apply
    systemctl restart networking
}


function interfaces_file_enable () {
    prefix_to_netmask
    echo $netmask
cat <<EOF > /etc/network/interfaces
auto lo
iface lo inet loopback

auto $nic1
iface $nic1 inet manual
    bond-master bond0

auto $nic2
iface $nic2 inet manual
    bond-master bond0

auto bond0
    iface bond0 inet static
    address $ip
    netmask $netmask
    gateway $gateway
    dns-nameservers 66.96.80.43 66.96.80.194
    bond-miimon 100
    bond-mode 802.3ad
    bond-xmit-hash-policy layer3+4
    bond-lacp-rate 1

EOF
    systemctl restart networking
}


function interfaces_file_disable () {
    prefix_to_netmask
cat <<EOF > /etc/network/interfaces
auto lo
iface lo inet loopback

auto $nic1
iface $nic1 inet static
    address $ip
    netmask $netmask
    gateway $gateway
EOF
    ip link delete dev bond0
    systemctl restart networking
}


function ubuntu_enable_bond () {
    apt -y install ifenslave
    modprobe bonding
    echo "bonding" >> /etc/modules
    if [[ -d "/etc/netplan" ]];then
        echo "netplan detected"
        netplan_enable
    elif [[ `cat /etc/network/interfaces` ]];then
        interfaces_file_enable
    fi
}


function ubuntu_disable_bond () {
    if [[ -d "/etc/netplan" ]];then
        netplan_disable
    elif [[ `cat /etc/network/interfaces` ]];then
        interfaces_file_disable
    fi
    systemctl restart networking
}


function debian_enable_bond () {
    apt -y install ifenslave
    /usr/sbin/modprobe bonding
    echo "bonding" >> /etc/modules
    if [[ -d "/etc/netplan" ]];then
        netplan_enable
    elif [[ `cat /etc/network/interfaces` ]];then
        interfaces_file_enable
    fi
}


function debian_disable_bond () {
    get_nics
    get_ips
    if [[ -d "/etc/netplan" ]];then
        netplan_disable
    elif [[ `cat /etc/network/interfaces` ]];then
        interfaces_file_disable
    fi
}


function proxmox_enable_bond () {
    cp /etc/network/interfaces /etc/network/interfaces.backup
cat <<EOF > /etc/network/interfaces.new
auto lo
iface lo inet loopback

auto $nic1
iface $nic1 inet manual
    bond-master bond0

auto $nic2
iface $nic2 inet manual
    bond-master bond0

auto bond0
iface bond0 inet manual
    bond-slaves $nic1 $nic2
    bond-miimon 100
    bond-mode 802.3ad
    bond-xmit-hash-policy layer2+3

auto vmbr0
iface vmbr0 inet static   
    address $ip/$prefix
    gateway $gateway
    bridge-ports bond0
    bridge-stp off
    bridge-fd 0
EOF
echo "Rebooting in 1 minute."
shutdown -r 1
}


function proxmox_disable_bond () {
    cp /etc/network/interfaces /etc/network/interfaces.backup
cat <<EOF > /etc/network/interfaces.new
auto lo
iface lo inet loopback

iface $nic1 inet manual

iface $nic2 inet manual

auto vmbr0
iface vmbr0 inet static
        address $ip/$prefix
        gateway $gateway
        bridge-ports $nic1
        bridge-stp off
        bridge-fd 0
EOF
echo "Rebooting in 1 minute."
shutdown -r 1
}

function determine_distro() {
    #determine OS and Version
    if [[ `cat /etc/os-release |grep 'ID=' | grep 'debian'` ]];then
        distro=debian
    elif [[ `cat /etc/os-release |grep 'ID=' | grep 'ubuntu'` ]];then
        distro=ubuntu
    elif [[ `cat /etc/os-release |grep 'ID=' | grep 'centos'` ]];then
        distro=centos
    elif [[ `cat /etc/os-release |grep 'ID=' | grep 'alma'` ]];then
        distro=alma
    elif [[ `cat /etc/os-release |grep 'ID=' | grep 'rocky'` ]];then
        distro=rocky
    elif [[ `cat /etc/os-release |grep 'ID=' | grep 'cloudlinux'` ]];then
        distro=centos
    fi
    os=$(cat /etc/os-release |grep PRETTY_NAME | cut -f2 -d'=' | sed 's/"//g')
    echo "$os detected"
}


function centos () {
    if [[ $bond_disable == "y" ]];then
        centos_disable_bond
        systemctl restart network
    elif [[ $bond_enable == "y" ]];then
        centos_enable_bond
        systemctl restart network
    fi
}
function alma () {
    if [[ $bond_disable == "y" ]];then
        centos_disable_bond
        nmcli connection down bond0
        systemctl restart NetworkManager
        nmcli connection up $nic1
    elif [[ $bond_enable == "y" ]];then
        centos_enable_bond
        systemctl restart NetworkManager
        nmcli connection up bond0
        ip address delete "$ip/$prefix" dev $nic1
    fi
}
function rocky () {
    if [[ $bond_disable == "y" ]];then
        centos_disable_bond
        nmcli connection down bond0
        systemctl restart NetworkManager
        nmcli connection up $nic1
    elif [[ $bond_enable == "y" ]];then
        centos_enable_bond
        systemctl restart NetworkManager
        nmcli connection up bond0
        ip address delete "$ip/$prefix" dev $nic1
    fi
}
function ubuntu () {
    if [[ $bond_disable == "y" ]];then
        ubuntu_disable_bond
     elif [[ $bond_enable == "y" ]];then
        ubuntu_enable_bond
    fi
}
function debian () {
    if [[ $bond_disable == "y" ]];then
        if [[ -f "/etc/apt/sources.list.d/pve-enterprise.list" ]];then
            proxmox_disable_bond
        else
            debian_disable_bond
        fi
    elif [[ $bond_enable == "y" ]];then
        if [[ -f "/etc/apt/sources.list.d/pve-enterprise.list" ]];then
            proxmox_enable_bond
        else
            debian_enable_bond
        fi
    fi
}


function netmask_to_prefix () {
    case $netmask in
        0  ) prefix=24 ;;
        128) prefix=25 ;;
        192) prefix=26 ;;
        224) prefix=27 ;;
        240) prefix=28 ;;
        248) prefix=29 ;;
        252) prefix=30 ;;
        254) prefix=31 ;;
        255) prefix=32 ;;
        *  ) wait 1
    esac
}


function prefix_to_netmask () {
    case $prefix in
        24) netmask=255.255.255.0   ;;
        25) netmask=255.255.255.128 ;;
        26) netmask=255.255.255.192 ;;
        27) netmask=255.255.255.224 ;;
        28) netmask=255.255.255.240 ;;
        29) netmask=255.255.255.248 ;;
        30) netmask=255.255.255.252 ;;
        31) netmask=255.255.255.254 ;;
        32) netmask=255.255.255.255 ;;
        * ) wait 1
    esac
}


function calculate_gateway_mask () {
    prefix_to_netmask
    oldifs=$IFS
    IFS=. read -r i1 i2 i3 i4 <<< $ip
    IFS=. read -r m1 m2 m3 m4 <<< $netmask
    IFS=$oldifs
    network_address=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
    if [[ -z "$gateway" ]];then
        gateway=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$(($((i4 & m4))+1))")
    fi
}
function calculate_gateway_prefix () {
    netmask_to_prefix
    oldifs=$IFS
    IFS=. read -r i1 i2 i3 i4 <<< $ip
    IFS=. read -r xx m1 m2 m3 m4 <<< $(for a in $(seq 1 32); do if [[ $(((a - 1) % 8)) -eq 0 ]]; then echo -n .; fi; if [[ $a -le $prefix ]]; then echo -n 1; else echo -n 0; fi; done)
    IFS=$oldifs
    network_address=$(printf "%d.%d.%d.%d\n" "$((i1 & (2#$m1)))" "$((i2 & (2#$m2)))" "$((i3 & (2#$m3)))" "$((i4 & (2#$m4)))")
    if [[ -z "$gateway" ]];then
        gateway=$(printf "%d.%d.%d.%d\n" "$((i1 & (2#$m1)))" "$((i2 & (2#$m2)))" "$((i3 & (2#$m3)))" "$(($((i4 & (2#$m4)))+1))")
    fi
}


function printUsage () {
cat <<EOF
This script is meant to make configuring IPs and network bonds easier.

It is capable of changing an IP or setting one if one doesn't exist.

It can also enable or disable 802.3ad NIC Bonding.

----------------------------WARNING----------------------------------
This script assumes the server you're configuring only has 1 IP on it.

If this server has more than 1 IP or is meant to have more than 1 IP,
please do the network configuration another way.  This script will only
allow 1 IP and would remove any others configured on the server.
---------------------------------------------------------------------

Usage:

(-s) - Set IP (with option to enable or disable bonding)
(-h) - Help (This message)
(-e) - Enable Bonding
(-d) - Disable Bonding
(-b) - Switch Bonding
(-n) - Fix NOCPS Vlan 11 remnants
(-u) - Unattended
(-p) - Primary NIC only / Single NIC bond (for shared ipmi systems)

EOF
}


function run_configure () {
    if [[ $unattended == "y" ]];then
        if [[ -f /opt/scripts/ips.txt ]];then
            bonded=$(cat /opt/scripts/ips.txt | grep bond | awk '{print $2}')
            if [[ $bonded == "true" ]];then
                bond_enable="y"
                bond_disable=""
            elif [[ $bonded == "false" ]];then
                bond_enable=""
                bond_disable="y"
            fi
        fi
    fi
    determine_distro
    get_nics
    if [[ ! $ip_set == "true" ]];then
        get_ips
    fi
    if [[ `ip a | grep bond` ]] && [[ $switch_bond == "y" ]];then
        bond_disable="y"
    elif [[ ! `ip a | grep bond` ]] && [[ $switch_bond == "y" ]];then
        bond_enable="y"
    fi
    case $distro in
        centos) centos ;;
        alma  ) alma   ;;
        rocky ) rocky  ;;
        ubuntu) ubuntu ;;
        debian) debian ;;
        *     ) echo "This OS is currently unsupported or unrecognized."
    esac
}


function fix_nocps () {
    determine_distro
    get_ips
    until [[ ! `ip ro | grep default` ]];do
        ip ro del default
    done
    ip_set="true"
    calculate_gateway_mask
    run_configure
    ip addr flush dev $nic2
    ip ro flush dev $nic2
}


#make sure we're running bash
if [ ! "$BASH_VERSION" ] ; then
    exec /bin/bash "$0" "$@"
fi


# Options.
if (($# == 0)); then
    printUsage
fi
while getopts ":shedbnu" option; do
echo $option
    case "${option}" in    
        s)
        configure_ip
        ;;        
        e)
        bond_enable="y"
        run_configure
        ;;
        d)
        bond_disable="y"
        run_configure
        ;;
        b)
        switch_bond="y"
        run_configure
        ;;
        n)
        bond_disable="y"
        fix_nocps
        ;;
        u)
        bond_enable="y"
        unattended="y"
        run_configure
        ;;
        p)
        bond_enable="y"
        unattended="y"
        primary_only="y"
        run_configure
        ;;
        \? | h | *)
        printUsage
        ;;
    esac
done
shift $((OPTIND - 1))




:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0982 ]--