#!/bin/bash
# Author: p
# date modified: 2021-05-28
#
#ngrep_logs () {
#netstat -ntu   | grep "$ngrepIP"  
#lsof -i -n | grep "$ngrepIP"
#
#egrep $ngrepIP /usr/local/apache/{domlogs,logs}/* /var/log/nginx/access_log 2/dev/null 
#}
#!/bin/bash

# Check if the first argument is a valid IP address
if [[ ! $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
    echo "Invalid IP address provided as the first argument."
    exit 1
   else
    ngrepIP="$1"

# basic net connections list
basic_function() {
 echo "=== netstat + lsof results of IP ==="
 netstat -ntu   | grep "$ngrepIP"  
 lsof -i -n | grep "$ngrepIP"
}

# basic + log results
full_function() {
 echo "=== netstat+lsof+logs ==="
 egrep $ngrepIP /usr/local/apache/{domlogs,logs}/* /var/log/nginx/access_log /usr/local/cpanel/logs/access_log 2>/dev/null
}
fi

# basic + log results
if [[ -z $2 ]]; then
    # Run basic_function when the second argument is empty
    basic_function
elif [[ $2 == "-a" ]]; then
    # Run full_function when the second argument is "-a"
    full_function
else
    echo "Invalid second argument."
    exit 1
fi

