Skip to content

Instantly share code, notes, and snippets.

View hvelarde's full-sized avatar

Héctor Velarde hvelarde

View GitHub Profile
# get total requests by status code
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
# get top requesters by IP
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head | awk -v OFS='\t' '{"host " $2 | getline ip; print $0, ip}'
# get top requesters by user agent
awk -F'"' '{print $6}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# get top requests by URL
@hvelarde
hvelarde / subdomains.sh-session
Created October 20, 2023 22:54
Search for and resolve subdomain names
$ snap install amass
...
$ amass enum -d cicese.mx -src
[DNS] cicese.mx
[HackerTarget] imp-udb10.cicese.mx
[HackerTarget] wireless-oc211.cicese.mx
[RapidDNS] dhcp-ac14.cicese.mx
[HackerTarget] pc-lankahuasa1.cicese.mx
...
[RapidDNS] cicese-auditorio.cicese.mx
@hvelarde
hvelarde / capture.py
Created July 5, 2017 12:31
A context manager to capture stdout and stderr
import contextlib
@contextlib.contextmanager
def capture():
"""A context manager to capture stdout and stderr.
http://stackoverflow.com/a/10743550/644075
"""
import sys
from cStringIO import StringIO
@hvelarde
hvelarde / pre-commit
Created June 5, 2012 22:14
PEP 8 pre-commit hook
#!/bin/sh
# Modified from kevincal version in https://gist.github.com/810399
# The following is a list of the most common PEP 8 errors and warnings; to
# skip some just add them to the IGNORE variable (comma separated):
# E111 indentation is not a multiple of four
# E123 closing bracket does not match indentation of opening bracket's line
# E201 whitespace after '('
# E202 whitespace before ')'
@hvelarde
hvelarde / cleanup.py
Last active June 21, 2018 23:21
Clean up least used catalog keywords
# -*- coding: utf-8 -*-
from plone import api
import transaction
def get_least_used(limit=1):
"""List all keywords used up to limit times in content."""
catalog = api.portal.get_tool('portal_catalog')
keywords = catalog.uniqueValuesFor('Subject')
@hvelarde
hvelarde / normalize.py
Created June 21, 2018 23:20
Normalize catalog keywords
# -*- coding: utf-8 -*-
from plone import api
import transaction
def normalize():
"""Remove spare spaces and transform keywords to lowercase."""
catalog = api.portal.get_tool('portal_catalog')
results = catalog()
@hvelarde
hvelarde / spoof.py
Last active February 28, 2018 13:19
Spoofing request when running Zope from the command line
from plone import api
from zope.component.hooks import setSite
import transaction
def spoof_request(app):
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManager import setSecurityPolicy
from Testing.makerequest import makerequest
@hvelarde
hvelarde / github3.py example
Last active December 27, 2017 12:40
Getting your contributions on a GitHub organization using github3.py to access the GitHub API.
>>> user, password = 'hvelarde', 'password'
>>> from github3 import login
>>> g = login(user, password=password)
>>> o = g.organization('collective')
>>> g.ratelimit_remaining
3369
>>> my_stats = []
>>> for r in o.iter_repos():
... for c in r.iter_contributor_statistics():
... if user in repr(c.author):
@hvelarde
hvelarde / ok.py
Created December 18, 2017 21:55
"ok" probe for zc.monitor
import pkg_resources
import logging
logger = logging.getLogger('zc.monitor')
try:
pkg_resources.get_distribution('zc.monitor')
except pkg_resources.DistributionNotFound:
@hvelarde
hvelarde / haproxy.vcl
Created December 18, 2017 21:25
Varnish configuration to be used with HAProxy backends
vcl 4.0;
import directors;
# probe definition for health checks
probe healthcheck {
.interval = 2s;
.url = "/haproxy?monitor";
.timeout = 1s;