Skip to content

Instantly share code, notes, and snippets.

@qerub
Created June 23, 2013 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qerub/5845073 to your computer and use it in GitHub Desktop.
Save qerub/5845073 to your computer and use it in GitHub Desktop.
Making gethostbyaddr accessible in PostgreSQL via Python
CREATE PROCEDURAL LANGUAGE 'plpythonu';
CREATE OR REPLACE FUNCTION gethostbyaddr(address text)
RETURNS text
LANGUAGE plpythonu
AS $$
import socket
try:
return socket.gethostbyaddr(address)[1][0]
except:
return None
$$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment