Skip to content

Instantly share code, notes, and snippets.

@o0-o
o0-o / enable_ssh_on_edgeos_via_https.sh
Last active June 11, 2022 22:50
[Enable SSH on a Ubiquiti EdgeRouter via HTTPS] Non-interactively Enable SSH on an EdgeOS Device with cURL #bash #edgemax #edgerouter #edgeos #ubiquit
#!/usr/bin/env bash
ROUTER_IP="192.168.1.1"
COOKIES="$(curl -v "https://${ROUTER_IP}/" \
-H 'Connection: keep-alive' \
-H 'Cache-Control: max-age=0' \
-H "Origin: https://${ROUTER_IP}" \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'DNT: 1' \
@o0-o
o0-o / install_ssh_key_on_edgeos_via_ssh.exp
Last active April 16, 2023 05:40
[Install an SSH Key in EdgeOS via SSH] Non-interactive Installation of SSH key on an EdgeOS Device #edgemax #edgerouter #edgeos #expect #ubiquiti
#!/usr/bin/env expect
# USAGE: ./install_ssh_key_on_edgeos_via_ssh.exp 192.168.1.1 ubnt ubnt #EdgeOS Defaults
# WARNING: This script will delete any existing keys on local and remote hosts for the specified user
set timeout 8
set host [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
@o0-o
o0-o / enable_ssh_on_edgeswitch_via_telnet.exp
Last active August 19, 2022 23:19
[Enable SSH on a Ubiquiti EdgeSwitch via Telnet] Non-interactively Enable SSH on an EdgeSwitch via Telnet #expect #ubiquiti #edgemax #edgeswitch
#!/usr/bin/env expect
set timeout 4
set host [lindex $argv 0]
set user ubnt
set password ubnt
spawn telnet "$host"
expect {
@o0-o
o0-o / mem_modules.sh
Last active May 10, 2019 15:51
[Memory Modules] Prints detailed information about memory modules installed on the host #Shell
# mem_modules.sh
# slot size type ecc make model serial
# linux/bsd x86
dmidecode --type memory |
grep --extended-regexp --regexp='^[[:space:]]*Size:|^[[:space:]]*Locator:|^[[:space:]]*Type:|^[[:space:]]*Type Detail:|^[[:space:]]*Manufacturer:|^[[:space:]]*Serial Number:|^[[:space:]]*Part Number:' |
sed 's/^[[:space:]]*Size: /@\&/g' | #add @& placeholder for beginning of each valid entry
sed 's/^.*: //g' | #remove labels
sed 's/[[:space:]]*$//g' | #remove trailing whitespace
tr '\n' '\t' | #tab delimit
@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
@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 / 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 / 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 / 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 / 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 |