You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the feature request is for a plugin or theme, specify it here.
Networking
I really like the items you have for checking different network items, I am building a modular script called ezsh that takes many different items that I have used throughout my SA roles, and finding others on the net. I came across yours and would like to add many of your functions to my script as well.
My changes
I am trying to make this system as functional compact as possible, so here is what I did with your script. (I may change it to use case instead of if, but everything works great.
#!/bin/zsh# https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/systemadmin/systemadmin.plugin.zshfunctionretlog() {
if [[ -z${1} ]];thenif [[ -f /var/log/nginx/access.log ]];thenecho'/var/log/nginx/access.log'elif [[ -f /var/log/httpd/access.log ]];thenecho'/var/log/httpd/access.log'elif [[ -f /var/log/apache/access.log ]];thenecho'/var/log/apache/access.log'elseprintf"%s""Could not find web server access log, specify its location"exit 127
fielseecho${1}fi
}
ip() {
# gather external ip 4 addressif [[ "${1}"=="external4" ]] || [[ "${1}"=="external" ]];then
curl -s -S -4 https://icanhazip.com
# gather external ip 6 addresselif [[ "${1}"=="external6" ]];then
curl -s -S -6 https://icanhazip.com
# determine local IP address(es)elif [[ "${1}"=="internal" ]];thenif((${+commands[ip]}));then
ip addr | awk '/inet /{print $2}'|command grep -v 127.0.0.1
else
ifconfig | awk '/inet /{print $2}'|command grep -v 127.0.0.1
fielseif [ -t 1 ];thencommand ip -c "$@"elsecommand ip "$@"fifi
}
# Sort connection stateconnections() {
local ezsh_conn_count
if [[ ${1}=="80" ]];then# View all 80 Port Connections
netstat -nat|grep -i ":80"|wc -l
elif [[ ${1}=="404" ]];then# Statistical connections 404
awk '($9 ~/404/)'"$(retlog[@])"| awk '{print $9,$7}'| sort
elif [[ ${1}=="ip" ]];then# On the connected IP sorted by the number of connections
netstat -ntu | awk '{print $5}'| cut -d: -f1 | sort | uniq -c | sort -n
elif [[ ${1}=="req" ]];then# top20 of Find the number of requests on 80 portif [[ "${2}"=="" ]];then
ezsh_conn_count=20
else
ezsh_conn_count=${2}fi
netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n ${ezsh_conn_count}elif [[ ${1}=="tcp4" ]];then# top20 of Using tcpdump ip 4 port 80 access to viewif [[ "${2}"=="" ]];then
ezsh_conn_count=20
else
ezsh_conn_count=${2}fi
curl -s -S -4 https://icanhazip.com
sudo tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"."'{print $1"."$2"."$3"."$4}'| sort | uniq -c | sort -nr |head -n ${ezsh_conn_count}elif [[ ${1}=="tcp6" ]];then# top20 of Using tcpdump ip 6 port 80 access to viewif [[ "${2}"=="" ]];then
ezsh_conn_count=20
else
ezsh_conn_count=${2}fi
curl -s -S -6 https://icanhazip.com
sudo tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"."'{print $1"."$2"."$3"."$4}'| sort | uniq -c | sort -nr |head -n ${ezsh_conn_count}elif [[ ${1}=="wait" ]];then# top20 of Find time_wait connectionif [[ "${2}"=="" ]];then
ezsh_conn_count=20
else
ezsh_conn_count=${2}fi
netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n ${ezsh_conn_count}elif [[ ${1}=="syn" ]];then# top20 of Find SYN connectionif [[ "${2}"=="" ]];then
ezsh_conn_count=20
else
ezsh_conn_count=${2}fi
netstat -an | grep SYN | awk '{print $5}'| awk -F: '{print $1}'| sort | uniq -c | sort -nr|head -n ${ezsh_conn_count}elif [[ ${1}=="proc" ]];then# Printing process according to the port number
netstat -ntlp | grep "${1:-.}"| awk '{print $7}'| cut -d/ -f1
elif [[ ${1}=="access" ]];then# top10 of gain access to the ip addressif [[ "${2}"=="" ]];then
ezsh_conn_count=10
else
ezsh_conn_count=${2}fi
awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}'"$(retlog[@])"elif [[ ${1}=="visits" ]];then# top20 of Most Visited file or pageif [[ "${2}"=="" ]];then
ezsh_conn_count=20
else
ezsh_conn_count=${2}fi
awk '{print $11}'"$(retlog[@])"|sort|uniq -c|sort -nr|head -n ${ezsh_conn_count}elif [[ ${1}=="pages" ]];then# top100 of Page lists the most time-consuming (more than 60 seconds) as well as the corresponding page number of occurrencesif [[ "${2}"=="" ]];then
ezsh_conn_count=100
else
ezsh_conn_count=${2}fi
awk '($NF > 60 && $7~/\.php/){print $7}'"$(retlog[@])"|sort -n|uniq -c|sort -nr|head -n ${ezsh_conn_count}elif [[ ${1}=="traffic" ]];then# Website traffic statistics (G)
awk "{sum+=$10} END {print sum/1024/1024/1024}""$(retlog[@])"elif [[ ${1}=="status" ]];then# Statistical http status.
awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}'"$(retlog[@])"else
netstat -nat | awk '{print $6}'|sort|uniq -c|sort -rn
fi
}
If the feature solves a problem you have, specify it here.
Describe the proposed feature.
With the code written that way, I now have 2 commands ip and connection, with an added argument
ip external || ip external4 || ip external6 || ip a, etc
connection [[options]]
I hope you like it, and are free to use it if you like.
Describe alternatives you've considered
No response
Additional context
No response
Related Issues
No response
The text was updated successfully, but these errors were encountered:
If the feature request is for a plugin or theme, specify it here.
Networking
I really like the items you have for checking different network items, I am building a modular script called ezsh that takes many different items that I have used throughout my SA roles, and finding others on the net. I came across yours and would like to add many of your functions to my script as well.
My changes
I am trying to make this system as functional compact as possible, so here is what I did with your script. (I may change it to use case instead of if, but everything works great.
If the feature solves a problem you have, specify it here.
Describe the proposed feature.
With the code written that way, I now have 2 commands
ip
andconnection
, with an added argumentip external || ip external4 || ip external6 || ip a, etc
connection [[options]]
I hope you like it, and are free to use it if you like.
Describe alternatives you've considered
No response
Additional context
No response
Related Issues
No response
The text was updated successfully, but these errors were encountered: