Personal tools
You are here: Home diverse filer til download mm. ipsort.py
Document Actions

ipsort.py

by admin last modified 2007-07-10 15:15

http://www.eksperten.dk/spm/786985

Click here to get the file

Size 1.3 kB - File type text/python-source

File contents

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Sorter ip på en pæn måde"""
Page = """Content-type: text/html

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Se og hent kildekoden <a target="_blank" href="http://www.databassen.dk:8090/bauerdata/python-program-eksempler/ipsort.py">her</a>
<hr>
<h3>Inddata</h3>
<pre>
%(indData)s
</pre>
<h3>Uddata</h3>
<pre>
%(udData)s
</pre>
<hr>
<b>Python er nemt, Python er sjovt.</b>
</html>
"""

def sortIps( ipListe ):
    L = []
    for ip in ipListe:
        ip =  [ "%03d" % int(x) for x in  ip.split( "." ) ]
        nyIp = ".".join( ip )
        L.append( nyIp )
    L.sort()    
    return L
if __name__ == "__main__":
    from pprint import pprint
    ipListe = [ "201.63.7.194",
    "81.101.81.117",
    "222.255.236.10",
    "122.153.153.131",
    "210.51.174.230",
    "210.75.208.10",
    "89.149.195.132",
    "202.69.160.5",
    "222.106.110.103",
    "201.216.248.113",
    "125.210.228.136",
    "72.1.208.109",
    "218.108.233.160",
    "81.222.103.2",
    "124.128.85.36",
    "86.98.59.157",
    "66.219.41.227",
    "219.234.86.98",
    "218.6.197.37",
    "168.95.192.3",
    "61.57.160.70",
    ]
    indData = "\n".join( ipListe )
    udData = "\n".join( sortIps( ipListe ) )
    print Page % vars() 

Related content
« May 2012 »
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Chat Rooms
CMS ?

Sparer man tid og penge på Plone

ja
nej
ved ikke

Dyrk motion

Trim ballerup

 

Powered by Plone, the Open Source Content Management System