Advertisement
xGHOSTSECx

Operational Security Protocol System

Dec 29th, 2023
1,998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.82 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Advanced Network Management Tool
  4.  
  5. function display_basic_info() {
  6.   clear
  7.   echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
  8.   echo "Hostname: $(hostname)"
  9.   echo "Kernel version: $(uname -r)"
  10.   echo "----------"
  11.   echo "Network interfaces:"
  12.   ifconfig -a
  13.   echo "----------"
  14.   echo "Routing table:"
  15.   route -n
  16.   echo "----------"
  17.   echo "DNS servers:"
  18.   cat /etc/resolv.conf
  19.   echo "----------"
  20.   echo "Listening ports:"
  21.   netstat -tulpn
  22.   echo -e "\nPress enter to return to the main menu."
  23.   read -r
  24. }
  25.  
  26. function configure_network_interface() {
  27.   clear
  28.   echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
  29.   echo "Enter the name of the network interface to configure:"
  30.   read interface_name
  31.  
  32.   if [[ -z "$interface_name" ]]; then
  33.     echo "Interface name cannot be empty."
  34.     read -r
  35.     return
  36.   fi
  37.  
  38.   PS3="Choose an action for $interface_name: "
  39.   actions=("Set IP address and subnet mask" "Set gateway" "Restart network interface" "Enable/Disable interface" "View interface details" "Cancel")
  40.   select action in "${actions[@]}"; do
  41.     case $action in
  42.       "Set IP address and subnet mask")
  43.         echo "Enter new IP address and subnet mask (e.g., 192.168.1.2/24):"
  44.         read ip_address
  45.         if [[ -n "$ip_address" ]]; then
  46.           ifconfig $interface_name $ip_address
  47.         else
  48.           echo "IP address cannot be empty."
  49.         fi
  50.         ;;
  51.       "Set gateway")
  52.         echo "Enter new gateway IP address:"
  53.         read gateway
  54.         if [[ -n "$gateway" ]]; then
  55.           route add default gw $gateway $interface_name
  56.         else
  57.           echo "Gateway IP address cannot be empty."
  58.         fi
  59.         ;;
  60.       "Restart network interface")
  61.         echo "Restarting network interface $interface_name..."
  62.         ifdown $interface_name && ifup $interface_name
  63.         ;;
  64.       "Enable/Disable interface")
  65.         PS3="Choose action for interface $interface_name: "
  66.         enable_actions=("Enable" "Disable" "Cancel")
  67.         select enable_choice in "${enable_actions[@]}"; do
  68.           case $enable_choice in
  69.             "Enable")
  70.               ifconfig $interface_name up
  71.               ;;
  72.             "Disable")
  73.               ifconfig $interface_name down
  74.               ;;
  75.             "Cancel")
  76.               break
  77.               ;;
  78.             *)
  79.               echo "Invalid choice."
  80.               ;;
  81.           esac
  82.           break
  83.         done
  84.         ;;
  85.       "View interface details")
  86.         echo "Details for interface $interface_name:"
  87.         ifconfig $interface_name
  88.         ;;
  89.       "Cancel")
  90.         break
  91.         ;;
  92.       *)
  93.         echo "Invalid choice."
  94.         ;;
  95.     esac
  96.     break
  97.   done
  98.   read -r
  99. }
  100.  
  101. function create_captive_portal() {
  102.   clear
  103.   echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
  104.   echo "Enter the network interface for the captive portal:"
  105.   read portal_interface
  106.  
  107.   if [[ -z "$portal_interface" ]]; then
  108.     echo "Interface name cannot be empty."
  109.     read -r
  110.     return
  111.   fi
  112.  
  113.   echo "Enter the URL to redirect users (e.g., http://captive-portal.com):"
  114.   read portal_url
  115.  
  116.   if [[ -z "$portal_url" ]]; then
  117.     echo "Portal URL cannot be empty."
  118.     read -r
  119.     return
  120.   fi
  121.  
  122.   echo "Creating captive portal on $portal_interface..."
  123.   iptables -t nat -A PREROUTING -i $portal_interface -p tcp --dport 80 -j DNAT --to-destination $portal_url:80
  124.   iptables -t nat -A POSTROUTING -j MASQUERADE
  125.   echo -e "\nCaptive portal created successfully.\nPress enter to return to the main menu."
  126.   read -r
  127. }
  128.  
  129. function utilize_loopback_localhost() {
  130.   clear
  131.   echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
  132.   PS3="Choose an action for loopback and localhost: "
  133.   loopback_actions=("Share internet connection with loopback" "Simulate printer for HTTP traffic masking" "Cancel")
  134.   select loopback_choice in "${loopback_actions[@]}"; do
  135.     case $loopback_choice in
  136.       "Share internet connection with loopback")
  137.         echo "Sharing internet connection with loopback..."
  138.         iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
  139.         ;;
  140.       "Simulate printer for HTTP traffic masking")
  141.         echo "Simulating printer for HTTP traffic masking..."
  142.         iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port 8080
  143.         ;;
  144.       "Cancel")
  145.         break
  146.         ;;
  147.       *)
  148.         echo "Invalid choice."
  149.         ;;
  150.     esac
  151.     break
  152.   done
  153.   read -r
  154. }
  155.  
  156. function configure_microsegmentation() {
  157.   clear
  158.   echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
  159.   echo "Enter the subnet for microsegmentation (e.g., 192.168.2.0/24):"
  160.   read subnet
  161.  
  162.   if [[ -z "$subnet" ]]; then
  163.     echo "Subnet cannot be empty."
  164.     read -r
  165.     return
  166.   fi
  167.  
  168.   echo "Enter the network interface for microsegmentation:"
  169.   read microsegment_interface
  170.  
  171.   if [[ -z "$microsegment_interface" ]]; then
  172.     echo "Interface name cannot be empty."
  173.     read -r
  174.     return
  175.   fi
  176.  
  177.   echo "Configuring microsegmentation on $microsegment_interface for $subnet..."
  178.   iptables -A FORWARD -i $microsegment_interface -s $subnet -j ACCEPT
  179.   iptables -A FORWARD -o $microsegment_interface -d $subnet -j ACCEPT
  180.   echo -e "\nMicrosegmentation configured successfully.\nPress enter to return to the main menu."
  181.   read -r
  182. }
  183.  
  184. function display_help() {
  185.   clear
  186.   echo -e "\e[1;34mAdvanced Network Management Tool - Help Menu\e[0m\n"
  187.   echo "1. Display basic network information: Displays information about the host, kernel, network interfaces, routing table, DNS servers, and listening ports."
  188.   echo "2. Configure network interface: Allows configuration of a network interface, including setting IP address, gateway, restarting, enabling/disabling, and viewing details."
  189.   echo "3. Create captive portal: Sets up a captive portal on a specified network interface, redirecting users to a provided URL."
  190.   echo "4. Utilize loopback and localhost: Provides options to share the internet connection with loopback or simulate a printer for HTTP traffic masking."
  191.   echo "5. Configure microsegmentation: Enables microsegmentation for a specified subnet on a network interface."
  192.   echo "6. Exit: Exits the tool."
  193.  
  194.   echo -e "\nExamples:"
  195.   echo "  To display basic network information: Choose option 1 from the main menu."
  196.   echo "  To configure a network interface: Choose option 2 and follow the prompts."
  197.   echo "  To create a captive portal: Choose option 3 and provide the required information."
  198.   echo "  To utilize loopback and localhost: Choose option 4 and select the desired action."
  199.   echo "  To configure microsegmentation: Choose option 5 and provide the subnet and interface details."
  200.   echo -e "  To exit: Choose option 6 from the main menu.\nPress enter to return to the main menu."
  201.   read -r
  202. }
  203.  
  204. function main_menu() {
  205.   while true; do
  206.     clear
  207.     echo -e "\e[1;34mAdvanced Network Management Tool\e[0m\n"
  208.     PS3="Select an option: "
  209.     main_actions=("Display basic network information" "Configure network interface" "Create captive portal" "Utilize loopback and localhost" "Configure microsegmentation" "Help" "Exit")
  210.     select main_choice in "${main_actions[@]}"; do
  211.       case $main_choice in
  212.         "Display basic network information")
  213.           display_basic_info
  214.           ;;
  215.         "Configure network interface")
  216.           configure_network_interface
  217.           ;;
  218.         "Create captive portal")
  219.           create_captive_portal
  220.           ;;
  221.         "Utilize loopback and localhost")
  222.           utilize_loopback_localhost
  223.           ;;
  224.         "Configure microsegmentation")
  225.           configure_microsegmentation
  226.           ;;
  227.         "Help")
  228.           display_help
  229.           ;;
  230.         "Exit")
  231.           echo "Exiting..."
  232.           exit 0
  233.           ;;
  234.         *)
  235.           echo "Invalid choice."
  236.           ;;
  237.       esac
  238.     done
  239.   done
  240. }
  241.  
  242. main_menu
  243.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement