Skip to content

Instantly share code, notes, and snippets.

@o0-o
o0-o / net_if.sh
Last active May 7, 2019 02:31
[Network Interfaces] Prints network interfaces #Shell
# net_if.sh
( # linux
file /sys/class/net/* |
sed 's/.*\///g' ||
# macos
networksetup -listallhardwareports |
grep "Device:" |
awk '{ print $2 }' ||
@o0-o
o0-o / net_mac_addresses.sh
Last active September 7, 2023 20:02
[MAC Addresses] Prints MAC addresses #Shell
# net_mac_addresses.sh
( # linux (NetworkManager)
nmcli -terse -fields GENERAL.HWADDR device show ||
# macos
networksetup -listallhardwareports ||
# linux/bsd
( ip address || ifconfig ) |
@o0-o
o0-o / uuid.sh
Last active May 7, 2019 02:30
[UUID] Prints a randomly generated UUID #Shell
# uuid.sh
uuidgen 2>/dev/null ||
exit 1 #fail
exit 0 #success
@o0-o
o0-o / password.sh
Last active May 7, 2019 02:29
[Generate Password] Generate a long random password #Shell
# password.sh
declare -r length=$(($(($RANDOM%17))+23)) 2>/dev/null && #23-39
( #openssl
openssl rand -base64 "${length-32}" ||
#os random
base64 < /dev/urandom |
fold --width="${length-32}" |
@o0-o
o0-o / cpu_model.sh
Last active May 7, 2019 01:13
[CPU Model] Print the make of the CPU #Shell
# cpu_model.sh
( # linux (proc)
grep "model name" /proc/cpuinfo |
uniq |
sed 's/[[:space:]]\{1,\}/ /g' |
sed 's/^model name : //' ||
# linux (lscpu)
lscpu |
@o0-o
o0-o / os.sh
Last active May 7, 2019 02:30
[Operating System] Prints the operating system #Shell
# os.sh
( # linux
grep ^ID= /etc/os-release |
sed 's/PRETTY_NAME=//' |
sed 's/"//g' ||
# macos
system_profiler SPSoftwareDataType |
grep "System Version: " |
@o0-o
o0-o / user.sh
Last active May 7, 2019 02:30
[User] Prints current user #Shell
# user.sh
whoami 2>/dev/null ||
exit 1 #failure
exit 0 #success
@o0-o
o0-o / users_loggedin.sh
Last active May 7, 2019 02:28
[Users Logged In] Prints all users currently logged in #Shell
# users_loggedin.sh
w -h |
awk '{ print $1 }' 2>/dev/null ||
exit 1 #failure
exit 0 #success
@o0-o
o0-o / cpu_arch.sh
Last active May 7, 2019 02:26
[CPU Architecture] Prints the CPU architecture #Shell
# cpu_arch.sh
uname -m |
sed 's/amd64/x86_64/' || #x86_64 is the generic name for amd64
exit 1 #failure
exit 0 #success
#https://forums.fedoraforum.org/showthread.php?186239-x86_64-vs-amd64
@o0-o
o0-o / net_nics.sh
Last active May 7, 2019 23:27
[Network Interface Cards] Prints NICs installed on the host #Shell
# net_nics.sh
set -o pipefail &&
( #macos
system_profiler SPEthernetDataType |
grep "BSD name" -B 11 | #hardware NICs have BSD names (excludes virtual interaces and bridges)
grep -v -E "Name|Type|Bus|ID|Sub|Link" | #remove lines we're not concerned with
sed 's/BSD name://g' | #remove labels
sed 's/://g' | #remove colons