Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7617961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:16:35+00:00 2026-05-31T03:16:35+00:00

The below is a part of a script i’m trying to write. The script

  • 0

The below is a part of a script i’m trying to write. The script opens my iptables log, each line in the log contains the details in the example below.

#example of a single line
#Mar  9 14:57:51 machine kernel: [23780.638839] IPTABLES Denied UDP: IN=p21p1 OUT= MAC=ff:ff:ff:ff:ff:ff:00:00:00:00:00:00:00:00 SRC=10.100.1.4 DST=10.100.1.63 LEN=78 TOS=0x00 PREC=0x00 TTL=128 ID=10898 PROTO=UDP$

# Read file in a line at a time
for line in iptables_log.readlines():
    #find time based on 4 letters, 2 spaces, up to 2 numbers, 1 space, then standard 10:10:10 time format
    time = re.findall('(^\w{1,4}\s\s\d{1,2}\s\d\d:\d\d:\d\d)', line)
    #mac lookup
    mac = re.findall('MAC=(?:\w\w:\w\w:\w\w:\w\w\:\w\w:\w\w:\w\w:\w\w:\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)', line)
    #source port
    src = re.findall('SRC=(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})', line)
    #destination port
    dst = re.findall('DST=(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})', line)
    #protocol
    proto = re.findall('PROTO=(?:\w{3,4})', line)
    #sourceport
    sourceport = re.findall('SPT=(?:\w{1,5})', line)
    #destport
    destport = re.findall('DPT=(?:\w{1,5})', line)
    print time, mac, src, dst, proto, sourceport, destport
    print '======================================================'

I’m trying to get the script to print only the items i want, but when its output by the script it looks like this, which would seem to be a list. I want it to print without the [] ”. Looking online it seems like every variable (time, mac, src, etc) are a list themselves. I’m not sure how to combine them. I have seen reference to join but am not sure how to use it this example. Can someone assist please?

['Mar  9 14:57:51'] ['MAC=ff:ff:ff:ff:ff:ff:00:00:00:00:00:00:00:00'] ['SRC=10.100.1.4'] ['DST=10.100.1.63'] ['PROTO=UDP'] ['SPT=137'] ['DPT=137']
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:16:37+00:00Added an answer on May 31, 2026 at 3:16 am

    Why not just unpack your lists ?

    >>> time = [0]
    >>> [time] = time
    >>> time
    0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below I have a very simple example of what I'm trying to do. I
I am trying to write a VBA script which imports all of the Excel
When as part of shell script only one line is operating on a file
What you see below is a part of my script. The problem is that
The PL/SQL script shown below is failing to execute at line # 20: declare
I'm uploading some files. Below is part of the script for the upload (I'm
All the code/commands below are part of a PHP script that processes images from
I'm trying to write a simple script for a Google Docs Spreadsheet. The two
The snippet of the PHP script below works for the most part... except for
Below is part of the XML which I am processing with PHP's XSLTProcessor :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.