Skip to content

Instantly share code, notes, and snippets.

@blacklabssecurity
Last active September 2, 2018 23:39
Show Gist options
  • Save blacklabssecurity/ae9a117529389f70df6618f2706604a3 to your computer and use it in GitHub Desktop.
Save blacklabssecurity/ae9a117529389f70df6618f2706604a3 to your computer and use it in GitHub Desktop.

Revisions

  1. blacklabssecurity revised this gist Sep 2, 2018. 1 changed file with 25 additions and 28 deletions.
    53 changes: 25 additions & 28 deletions ipv4Configuration.sh
    Original file line number Diff line number Diff line change
    @@ -58,46 +58,43 @@ static_func () {
    echo "Restarting the network service..." && /etc/init.d/networking restart >/dev/null
    }

    echo "Let's test your Internet access now..."
    echo " This can be either a static or dynmaic configuration..."
    echo
    echo " Let's test your Internet access now..."
    sleep 1
    echo
    ping -c3 8.8.8.8 >/tmp/pingOutput

    if grep "bytes from" /tmp/pingOutput >/dev/null && grep "eth.* inet dhcp" /etc/network/interfaces >/dev/null; then
    echo "You are connected to the Internet through a DHCP configuration"
    if grep "bytes from" /tmp/pingOutput >/dev/null && grep "eth.* inet static" /etc/network/interfaces >/dev/null; then
    echo " You are connected to the Internet through a static configuration"

    elif
    grep "bytes from" /tmp/pingOutput >/dev/null && grep "eth.* inet static" /etc/network/interfaces >/dev/null; then
    echo "You are connected to the Internet through a static configuration"
    grep "bytes from" /tmp/pingOutput >/dev/null || grep "eth.* inet dhcp" /etc/network/interfaces >/dev/null; then
    echo " You are connected to the Internet through a DHCP configuration"

    else
    echo "You are not currently connected to the Internet"
    echo " You are not currently connected to the Internet"

    fi

    echo

    if ask "Would you like to adjust your IPv4 Address configuration? " Y; then
    echo "1. Configure a DHCP Address"
    echo "2. Configure a Static Address"
    echo "3. Leave as currently configured"
    echo
    echo
    echo -n "Choice: "
    read choice
    echo $choice
    # case use will create approach to ip configuration
    case $choice in
    1) dhcp_func;;
    2) static_func;;
    3) return;;
    while true; do
    echo " 1. Configure a DHCP Address"
    echo " 2. Configure a Static Address"
    echo " 3. Leave as currently configured"
    echo
    echo
    echo -n "Choice: "
    read choice

    fi

    rm -r /tmp/pingOutput

    echo "Your IP address configuration is stored in your /etc/network/interfaces file."
    echo
    read -n 1 -s -r -p "...Press any key to continue..."
    echo
    echo
    # case use will create approach to ip configuration
    case $choice in
    1) dhcp_func && break;;
    2) static_func && break ;;
    3) break;;
    *) echo " That is not a valid choice"
    esac
    done
    fi
  2. blacklabssecurity renamed this gist Sep 2, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. blacklabssecurity created this gist Sep 2, 2018.
    103 changes: 103 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,103 @@
    #!/bin/bash

    dhcp_func () {
    echo "Let's configure your IPv4 DHCP configuration."
    sed -i 's|static|dhcp|g' /etc/network/interfaces
    if /etc/network/interfaces | grep "address"; then
    sed -i 's|address.*|#address|g' /etc/network/interfaces
    fi

    if /etc/network/interfaces | grep "netmask"; then
    sed -i 's|netmask.*|#netmask|g' /etc/network/interfaces
    fi

    if /etc/network/interfaces | grep "broadcast"; then
    sed -i 's|broadcast.*|#broadcast|g' /etc/network/interfaces
    fi

    if /etc/network/interfaces | grep "gateway"; then
    sed -i 's|gateway.*|#gateway|g' /etc/network/interfaces
    fi

    if /etc/network/interfaces | grep ".*nameserver"; then
    sed -i 's|.*nameserver.*|#.*nameserver'
    fi

    if ask "Would you like to customize the DNS nameserver: " Y; then
    echo "Enter the DNS nameserver to use (Ex: 8.8.8.8 for Goolge DNS): "
    read dns
    echo "nameserver $dns" > /etc/resolv.conf
    fi
    echo "Restarting the network service..." && /etc/init.d/networking restart >/dev/null
    }

    static_func () {
    echo "Let's configure your IPv4 static configuration."
    sed -i 's|dhcp|static|g' /etc/network/interfaces

    echo "Enter the IP Address to set followed by [ENTER] : "
    read ipadd
    echo " address $ipadd" >> /etc/network/interfaces

    echo "Enter the Subnet Mask to set followed by [ENTER] : "
    read mask
    echo " netmask $mask" >> /etc/network/interfaces

    echo "Enter the Gateway Address to set followed by [ENTER] : "
    read gway
    echo " address $gway" >> /etc/network/interfaces

    echo "Enter the Broadcast Address to set followed by [ENTER] : "
    read bcast
    echo " address $bcast" >> /etc/network/interfaces

    echo "Enter the DNS nameserver to use (Ex: 8.8.8.8 for Goolge DNS): "
    read dns
    echo "nameserver $dns" > /etc/resolv.conf

    echo "Restarting the network service..." && /etc/init.d/networking restart >/dev/null
    }

    echo "Let's test your Internet access now..."
    sleep 1
    echo
    ping -c3 8.8.8.8 >/tmp/pingOutput

    if grep "bytes from" /tmp/pingOutput >/dev/null && grep "eth.* inet dhcp" /etc/network/interfaces >/dev/null; then
    echo "You are connected to the Internet through a DHCP configuration"

    elif
    grep "bytes from" /tmp/pingOutput >/dev/null && grep "eth.* inet static" /etc/network/interfaces >/dev/null; then
    echo "You are connected to the Internet through a static configuration"

    else
    echo "You are not currently connected to the Internet"

    fi

    echo

    if ask "Would you like to adjust your IPv4 Address configuration? " Y; then
    echo "1. Configure a DHCP Address"
    echo "2. Configure a Static Address"
    echo "3. Leave as currently configured"
    echo
    echo
    echo -n "Choice: "
    read choice
    echo $choice
    # case use will create approach to ip configuration
    case $choice in
    1) dhcp_func;;
    2) static_func;;
    3) return;;

    fi

    rm -r /tmp/pingOutput

    echo "Your IP address configuration is stored in your /etc/network/interfaces file."
    echo
    read -n 1 -s -r -p "...Press any key to continue..."
    echo
    echo