Skip to content

Instantly share code, notes, and snippets.

View rsperl's full-sized avatar

Richard rsperl

  • North Carolina, United States
View GitHub Profile
@rsperl
rsperl / copy_file_permissions.py
Last active July 25, 2022 14:20
copy file permissions from one file to another #snippet
import os, stat
st = os.stat(src_file_name)
mode = stat.S_IMODE(st.st_mode)
os.chmod(dest_file_name, mode)
@rsperl
rsperl / require_root.py
Last active July 25, 2022 14:49
check if file is run as root #snippet
import os, sys
if os.geteuid() != 0:
print 'You must be root to run this script'
sys.exit(0)
@rsperl
rsperl / nmap_examples.md
Last active May 21, 2025 03:30
nmap examples #snippet
@rsperl
rsperl / python_logger_debug.py
Last active July 25, 2022 13:51
debugging python loggers #snippet
#!/usr/bin/env python
# src: https://www.electricmonk.nl/log/2017/08/06/understanding-pythons-logging-module/
# check the logger and all its parents to cech the log level, name,
# and configured handlers
log_to_debug = logging.getLogger("myapp.ui.edit")
while log_to_debug is not None:
print("level: %s, name: %s, handlers: %s".format(
@rsperl
rsperl / find_and_pipe.yml
Last active July 25, 2022 14:42
use ansible to find a command and do something with it using the pipe lookup #nosnippet
---
# example of how to search a path for a file and do something with that file
# In this example we find a command (echo), then use the pipe lookup to
# run echo
- hosts: localhost
connection: local
gather_facts: no
@rsperl
rsperl / copy_string_network_netcat.sh
Last active July 25, 2022 14:21
Copy string to another host on the network #snippet
# start netcat listening on dest host:
nc -l 1234 | pbcopy
# send string to dest host via netcat:
echo $STR | nc 192.168.0.123 1234
@rsperl
rsperl / notes.md
Last active July 25, 2022 15:16
notes on installing perl packages, python modules, and compiling software #snippet
  • OS: Ubuntu 16.04
  • Error: can't find mysql_config
  • Solution: apt install -y libmysqlclient-dev

  • OS: Ubuntu 16.04
  • Error: can't find openssl.h
  • Solution: apt install -y libssl-dev

  • OS: Ubuntu
  • Error: libtool not found
@rsperl
rsperl / config
Last active July 25, 2022 14:45
ssh client config #snippet
Host *
ServerAliveCountMax 3
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
LogLevel ERROR
ServerAliveInterval 60
IdentityFile ~/.ssh/id_rsa
Host *.proxied.domain.com
ProxyCommand ssh proxyhost.domain.com nc %h %p
@rsperl
rsperl / detect_redirect_or_pipe.py
Last active July 25, 2022 14:01
Determine if script is being redirected or piped #snippet
import sys
if sys.stdout.isatty():
print("Not redirected or piped")
else:
print("Redirected or piped somewhere")
@rsperl
rsperl / dbdiff.py
Last active July 25, 2022 14:22
Find differences between two mysql databases #snippet
#!/usr/bin/env python
"""
Find the differences between two mysql databases.
"""
from __future__ import print_function
import os
import re
import sys