Python Statistics log IP occurrences

Source: Internet
Author: User

Cat Test

218.79.251.215--[23/may/2006:08:57:44 +0800] "Get/fg172.exe http/1.1" 206 2350253

220.178.150.3--[23/may/2006:08:57:40 +0800] "Get/fg172.exe http/1.1" 200 2350253

59.42.2.185--[23/may/2006:08:57:52 +0800] "Get/fg172.exe http/1.1" 200 2350253

219.140.190.130--[23/may/2006:08:57:59 +0800] "Get/fg172.exe http/1.1" 200 2350253

221.228.143.52--[23/may/2006:08:58:08 +0800] "Get/fg172.exe http/1.1" 206 719996

221.228.143.52--[23/may/2006:08:58:08 +0800] "Get/fg172.exe http/1.1" 206 713242

221.228.143.52--[23/may/2006:08:58:09 +0800] "Get/fg172.exe http/1.1" 206 1200250


Awk

awk ' {print '} ' test|uniq-c


Python

#!/usr/bin/env pythonfile = open (' Test ') done = 0list_ip = []while not  done:        line = file.readline ()          if line !=  ':                 line = line.strip (' \ n ')                  line_list = line.split ('   ', 1)                 list _ip.append (line_list[0])         else:                 done = 1file.close () ip_test =  list (Set (LIST_IP)) For ip in ip_test:        print   "%s %s"  %  (List_ip.count (IP), IP) 


This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1575010

Python Statistics log IP occurrences

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.