Skip to content

Instantly share code, notes, and snippets.

@kgaughan
kgaughan / gist:4ab0f0fca88838cfa280
Created May 29, 2015 15:26
Bad IP in autoritative section section: dns9.linuxpl.com should have 78.46.68.78 as its A record, not 144.76.189.18
% dig +aaonly @dns9.linuxpl.com admpassivewindows.ie ANY
; <<>> DiG 9.9.5-3ubuntu0.2-Ubuntu <<>> +aaonly @dns9.linuxpl.com admpassivewindows.ie ANY
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30496
;; flags: qr aa rd; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 3
;; WARNING: recursion requested but not available
@kgaughan
kgaughan / gist:d1498b42156ecb89980f
Created June 15, 2015 10:52
Sending an email from the shell
# To send a email, use the 'mailx' command. This takes the email to send on
# standard input. The -s flag is used to specify your subject, and the
# recipient address is specified without any flags. Everything after '--' is
# passed on to the Mail Transport Agent (MTA, the local mailserver), and the
# '-f' flag is used to specify the sender address, while '-F' is used to
# specify the sender name.
#
# See 'man 1 mailx' for details. The Debian packages you can use for this are
# 'bsd-mailx' or 'heirloom-mailx', though both present slightly different
# command line interfaces. I'm using 'bsd-mailx' here.
Jul 29 11:10:13 cian knot[86688]: notice: [talideon.eu] NOTIFY, incoming, 2a01:a8:dc2:33::33@53755: unauthorized request
Jul 29 11:10:13 cian knot[86688]: notice: [talideon.eu] NOTIFY, incoming, 78.153.202.4@5042: unauthorized request
Jul 29 11:10:21 cian knot[86688]: notice: [gaughan.me] NOTIFY, incoming, 78.153.202.4@5042: unauthorized request
Jul 29 11:10:22 cian knot[86688]: notice: [gaughan.me] NOTIFY, incoming, 2a01:a8:dc2:33::33@33170: unauthorized request
Jul 29 11:10:25 cian knot[86688]: notice: [talideon.com] NOTIFY, incoming, 2a01:a8:dc2:33::33@13798: unauthorized request
Jul 29 11:10:25 cian knot[86688]: notice: [talideon.com] NOTIFY, incoming, 78.153.202.4@5042: unauthorized request
Jul 29 11:10:25 cian knot[86688]: notice: [stereochro.me] NOTIFY, incoming, 2a01:a8:dc2:33::33@12630: unauthorized request
Jul 29 11:10:25 cian knot[86688]: notice: [stereochro.me] NOTIFY, incoming, 78.153.202.4@5042: unauthorized request
~^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z](?:[a-z0-9-]*[a-z0-9])$~
function is_valid_local_part($local) {
// I'm not entirely sure about this regex, but it seems to fit was RFC2822 specifies.
return preg_match("@^[-a-z0-9!#\$%&'*+/=?^_`{|}~]+(\.[-a-z0-9!#\$%&'*+/=?^_`{|}~]+)*\$@", $local);
}
function is_well_formed_email_address($email) {
// We ignore legacy addresses and local addresses.
$parts = explode('@', $email, 2);
if (count($parts) != 2) {
return false;
function can_host_receive_mail($host) {
if (checkdnsrr($host, 'MX')) {
return true;
}
// We try the host itself if it exists no MX records were found, as per
// RFC2821.
if (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')) {
$h = @fsockopen($host, 25, $errno, $errstr, 30);
if ($h) {
fclose($h);
function is_well_formed_hostname($host) {
return preg_match('~^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z](?:[a-z0-9-]*[a-z0-9])$~', $host);
}
if (!is_well_formed_email_address($email)) {
echo "Email address is not well-formed.\n";
} else {
list(, $host) = explode('@', $email, 2);
if (can_host_receive_mail($host)) {
echo "Host $host can receive mail.\n";
} else {
echo "Host $host can't receive mail.\n";
}
}
#!/usr/bin/env python
#
# pipedarg
# by Keith Gaughan <http://talideon.com/>
#
# The software is hereby placed in the public domain, and the author
# disclaims ownership over it and all responsibility for any damage caused
# directly or indirectly through its use. It may be freely copied and/or
# mangled, provided that altered versions have a different name and are
# not attributed to the original author.
from itertools import count
def sieve():
"""
The Sieve of Erastosthenes.
If you wanted to speed this up, your best bets are to throw in a wheel.
The heapq module's already written in C, so that's as fast as it's going
to get, though if you can think of a way to avoid quite so many calls to
heapq.heapreplace() (or prevent if from sifting the heap prematurely for