Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Advanced Network Management Tool
- function display_basic_info() {
- clear
- echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
- echo "Hostname: $(hostname)"
- echo "Kernel version: $(uname -r)"
- echo "----------"
- echo "Network interfaces:"
- ifconfig -a
- echo "----------"
- echo "Routing table:"
- route -n
- echo "----------"
- echo "DNS servers:"
- cat /etc/resolv.conf
- echo "----------"
- echo "Listening ports:"
- netstat -tulpn
- echo -e "\nPress enter to return to the main menu."
- read -r
- }
- function configure_network_interface() {
- clear
- echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
- echo "Enter the name of the network interface to configure:"
- read interface_name
- if [[ -z "$interface_name" ]]; then
- echo "Interface name cannot be empty."
- read -r
- return
- fi
- PS3="Choose an action for $interface_name: "
- actions=("Set IP address and subnet mask" "Set gateway" "Restart network interface" "Enable/Disable interface" "View interface details" "Cancel")
- select action in "${actions[@]}"; do
- case $action in
- "Set IP address and subnet mask")
- echo "Enter new IP address and subnet mask (e.g., 192.168.1.2/24):"
- read ip_address
- if [[ -n "$ip_address" ]]; then
- ifconfig $interface_name $ip_address
- else
- echo "IP address cannot be empty."
- fi
- ;;
- "Set gateway")
- echo "Enter new gateway IP address:"
- read gateway
- if [[ -n "$gateway" ]]; then
- route add default gw $gateway $interface_name
- else
- echo "Gateway IP address cannot be empty."
- fi
- ;;
- "Restart network interface")
- echo "Restarting network interface $interface_name..."
- ifdown $interface_name && ifup $interface_name
- ;;
- "Enable/Disable interface")
- PS3="Choose action for interface $interface_name: "
- enable_actions=("Enable" "Disable" "Cancel")
- select enable_choice in "${enable_actions[@]}"; do
- case $enable_choice in
- "Enable")
- ifconfig $interface_name up
- ;;
- "Disable")
- ifconfig $interface_name down
- ;;
- "Cancel")
- break
- ;;
- *)
- echo "Invalid choice."
- ;;
- esac
- break
- done
- ;;
- "View interface details")
- echo "Details for interface $interface_name:"
- ifconfig $interface_name
- ;;
- "Cancel")
- break
- ;;
- *)
- echo "Invalid choice."
- ;;
- esac
- break
- done
- read -r
- }
- function create_captive_portal() {
- clear
- echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
- echo "Enter the network interface for the captive portal:"
- read portal_interface
- if [[ -z "$portal_interface" ]]; then
- echo "Interface name cannot be empty."
- read -r
- return
- fi
- echo "Enter the URL to redirect users (e.g., http://captive-portal.com):"
- read portal_url
- if [[ -z "$portal_url" ]]; then
- echo "Portal URL cannot be empty."
- read -r
- return
- fi
- echo "Creating captive portal on $portal_interface..."
- iptables -t nat -A PREROUTING -i $portal_interface -p tcp --dport 80 -j DNAT --to-destination $portal_url:80
- iptables -t nat -A POSTROUTING -j MASQUERADE
- echo -e "\nCaptive portal created successfully.\nPress enter to return to the main menu."
- read -r
- }
- function utilize_loopback_localhost() {
- clear
- echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
- PS3="Choose an action for loopback and localhost: "
- loopback_actions=("Share internet connection with loopback" "Simulate printer for HTTP traffic masking" "Cancel")
- select loopback_choice in "${loopback_actions[@]}"; do
- case $loopback_choice in
- "Share internet connection with loopback")
- echo "Sharing internet connection with loopback..."
- iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
- ;;
- "Simulate printer for HTTP traffic masking")
- echo "Simulating printer for HTTP traffic masking..."
- iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port 8080
- ;;
- "Cancel")
- break
- ;;
- *)
- echo "Invalid choice."
- ;;
- esac
- break
- done
- read -r
- }
- function configure_microsegmentation() {
- clear
- echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
- echo "Enter the subnet for microsegmentation (e.g., 192.168.2.0/24):"
- read subnet
- if [[ -z "$subnet" ]]; then
- echo "Subnet cannot be empty."
- read -r
- return
- fi
- echo "Enter the network interface for microsegmentation:"
- read microsegment_interface
- if [[ -z "$microsegment_interface" ]]; then
- echo "Interface name cannot be empty."
- read -r
- return
- fi
- echo "Configuring microsegmentation on $microsegment_interface for $subnet..."
- iptables -A FORWARD -i $microsegment_interface -s $subnet -j ACCEPT
- iptables -A FORWARD -o $microsegment_interface -d $subnet -j ACCEPT
- echo -e "\nMicrosegmentation configured successfully.\nPress enter to return to the main menu."
- read -r
- }
- function display_help() {
- clear
- echo -e "\e[1;34mAdvanced Network Management Tool - Help Menu\e[0m\n"
- echo "1. Display basic network information: Displays information about the host, kernel, network interfaces, routing table, DNS servers, and listening ports."
- echo "2. Configure network interface: Allows configuration of a network interface, including setting IP address, gateway, restarting, enabling/disabling, and viewing details."
- echo "3. Create captive portal: Sets up a captive portal on a specified network interface, redirecting users to a provided URL."
- echo "4. Utilize loopback and localhost: Provides options to share the internet connection with loopback or simulate a printer for HTTP traffic masking."
- echo "5. Configure microsegmentation: Enables microsegmentation for a specified subnet on a network interface."
- echo "6. Exit: Exits the tool."
- echo -e "\nExamples:"
- echo " To display basic network information: Choose option 1 from the main menu."
- echo " To configure a network interface: Choose option 2 and follow the prompts."
- echo " To create a captive portal: Choose option 3 and provide the required information."
- echo " To utilize loopback and localhost: Choose option 4 and select the desired action."
- echo " To configure microsegmentation: Choose option 5 and provide the subnet and interface details."
- echo -e " To exit: Choose option 6 from the main menu.\nPress enter to return to the main menu."
- read -r
- }
- function main_menu() {
- while true; do
- clear
- echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
- PS3="Select an option: "
- main_actions=("Display basic network information" "Configure network interface" "Create captive portal" "Utilize loopback and localhost" "Configure microsegmentation" "Help" "Exit")
- select main_choice in "${main_actions[@]}"; do
- case $main_choice in
- "Display basic network information")
- display_basic_info
- ;;
- "Configure network interface")
- configure_network_interface
- ;;
- "Create captive portal")
- create_captive_portal
- ;;
- "Utilize loopback and localhost")
- utilize_loopback_localhost
- ;;
- "Configure microsegmentation")
- configure_microsegmentation
- ;;
- "Help")
- display_help
- ;;
- "Exit")
- echo "Exiting..."
- exit 0
- ;;
- *)
- echo "Invalid choice."
- ;;
- esac
- done
- done
- }
- main_menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement