Skip to content

Instantly share code, notes, and snippets.

View theratman's full-sized avatar

Original RatMan theratman

View GitHub Profile
@theratman
theratman / observium_xinted_to_systemd.sh
Created January 17, 2023 19:43
Converting Observium xinetd service to systemd
cat << EOF > /etc/systemd/system/observium_agent\@.service
[Unit]
Description=Observium Agent Service
After=network.target observium_agent.socket
Requires=observium_agent.socket
[Service]
Type=simple
User=root
# Note the - to make systemd ignore the exit code
@theratman
theratman / dnsswitcher.command
Last active December 9, 2020 00:03
DNS Switcher: Change DNS service on Mac OS X (use «dialog» that need to be installed before): brew install dialog)
#!/usr/bin/env zsh
IFS=$'\n'
#/ Usage: dnsswitcher.sh
#/ Description: Change DNS service on Mac OS X
#/ Examples: ./dnsswitcher.sh
#/ Options:
#/ --help: Display this help message
usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; }
expr "$*" : ".*--help" > /dev/null && usage
@theratman
theratman / .zshrc
Last active October 17, 2019 14:22
Better PROMPT (aka PS1) for zsh @ Mac OS X Catalina 10.15
# Better PROMPT (aka PS1) for zsh @ Mac OS X Catalina 10.15
export PROMPT="╭─[%B%F{cyan}%n%f%F{red}@%f%F{magenta}%m%f:%b %F{green}%*%f]
╰─[%F{yellow}%~%f]
%(?.%F{green}.%F{red})%#%f "
export RPROMPT="%B%(?..%F{red}%? ↵%f)%b"
@theratman
theratman / Established_IP_on_port_80_and_443_v2.sh
Last active September 21, 2023 22:53
Show top established IP connections to the ports 80(http) and 443 (https). This scripts use ss (iproute package) and goiplookup to show IP geographic location.
#!/usr/bin/env bash
############################################################
# #
# Usage: ./Established_IP_on_port_80_and_443_v2.sh [all] #
# Show IPs TCP State Established, with argument show all #
# #
############################################################
# Color variables
@theratman
theratman / Established_IP_on_port_80_and_443.sh
Last active October 5, 2020 12:31
Show top established IP connections to the ports 80(http) and 443 (https). This scripts use netstat (net-tools package) and geoiplookup to show IPs and the geographic location of each IP.
#!/bin/bash
while true; do
clear
if [ $# -gt 0 ]; then
echo "All State: CLOSE_WAIT CLOSING ESTABLISHED FIN_WAIT1 FIN_WAIT2 LAST_ACK LISTEN SYN_RECV TIME_WAIT etc"
netstat -ant | awk '! /LISTEN $/ {split($4, a, ":", seps); if (a[2] == "80" || a[2] == "443") {m=split($5, b, ":", seps); print b[m-1]} }' | sort | uniq -c | sort -n | tail -20 | awk '{printf("%s -> ", $0); system("geoiplookup " $0 " | cut -d\\ -f4-")}'
else
echo "Only State: ESTABLISHED"
netstat -ant | awk '/ESTABLISHED$/ {split($4, a, ":", seps); if (a[2] == "80" || a[2] == "443") {m=split($5, b, ":", seps); print b[m-1]} }' | sort | uniq -c | sort -n | tail -20 | awk '{printf("%s -> ", $0); system("geoiplookup " $0 " | cut -d\\ -f4-")}'
fi
@theratman
theratman / change_filename_to_md5.sh
Last active June 18, 2023 20:04
Rename files to md5 sum plus extension
#!/bin/bash
# For Mac OS X version (md5)
MD="md5 -r"
# For Linux version (md5sum)
MD="md5sum"
for i in ./*; do
mv "${i}" "./$($MD "$i" | awk '{print $1}').${i##*.}"