#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # """Look up a service name by its port number. """ #end_pymotw_header import socket import urlparse for port in [ 80, 443, 21, 70, 25, 143, 993, 110, 995 ]: print urlparse.urlunparse( (socket.getservbyport(port), 'example.com', '/', '', '', '') )