Archive

标签为 ‘Python’的文章

How to convert SPP into text2pcap readable format by python

Introduction

There are some internal tools that can decode SPP packets at former, but they are not work now. In some scenario, customer coudln’t do span on our asr9k, so we only need SPP, then will face to how to decode SPP result.

The article disscuss how to covert SPP original data to text2pcap readable format, then decode by text2pcap. You only do the script that can auto work. Btw, before do that, you need have python2.7 and text2pcap (integrate in wireshark). If you have python3.0 or newer, that maybe have some issue, because some function have a bit different, you need adjust them by yourself.

Solution

Original SPP data:

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2017.12.04 17:12:19 =~=~=~=~=~=~=~=~=~=~=~=
trace p stop
Tracing stopped with 666 outstanding...
spp-ui> trace print
Packet serial 861
port4/classify:
  length 148 phys_int_index 0 next_ctx 0xdeadbeef time 09:10:41.407
  00: 00 70 72 00 00 08 00 65 7a 00 00 00 ff ff 00 07 
  10: 80 30 00 00 00 00 0f 00 00 00 1f 00 00 00 00 00 
  20: 00 70 05 f2 42 fb 00 00 04 00 01 40 07 01 05 27 
  30: 06 03 0e 06 00 00 00 00 4c 00 00 00 00 00 58 00 
  40: 00 00 00 00 00 00 06 01 00 a1 13 41 92 60 00 b2 
  50: 64 41 8a 4c 08 00 45 c0 00 3e 00 00 00 00 fe 11 
  60: c8 25 12 ac 79 0d 34 df d0 01 02 86 02 86 00 2a 
  70: 75 5a 00 01 00 1e 3f da a4 0f 00 00 01 00 00 14 
  80: 00 00 00 00 04 00 00 04 00 5a c0 00 04 01 00 04 
  90: 3f da a4 0f 00 00 00 00 00 00 00 00 00 00 00 00 
  a0: 00 00 00 17 00 08 05 01 00 00 af c8 00 24 14 01 
  b0: 01 08 3f da d0 46 20 00 01 08 3f da d0 42 20 00 
  c0: 01 08 3f da d0 41 20 00 01 08 3f da d0 07 20 00 
  d0: 00 08 13 01 00 00 08 00 00 20 cf 07 00 00 07 16 
  e0: 4d 50 4c 53 2d 54 45 20 74 6f 20 76 61 72 30 31 
  f0: 2e 6b 6c 70 30 32 00 00 00 0c 0b 07 3f df 04 08 
--------------------------

完整阅读

0

Auto check share memory utilization for IOX by Python

Introduction

In some scenario, we need to monitor some data in router/switch by automation. This article will show example that how to check share memory utilization. And you can easy to change the script base on your requirement/scenario.

Prepare

Due to “telnetlib” couldn’t exactly check expect messages by read_until() function (that couldn’t control exactly time when the info return to buffer), so I change to “expect”. And follow Bo’s example Python Expect Demo, and there is a good documents for expect demo from IBM too: 探索 Pexpect,第 2 部分:Pexpect 的实例分析
完整阅读

0

Python mini project backup

Python的课程终于结束了,真的很费时间,虽然拿到的分不高,但总算是从头到尾学了一遍,收获还是有的,下面是最终成绩:
Grade Achieved: 91.5% with Distinction

很期待用学到的知识去优化我之前写的CRT+python的脚本~
下面是课程备份,这些程序可能或多或少都存在一些问题,仅供自己以后复习:
Mini-project # 0 – “We want… a shrubbery!”
http://www.codeskulptor.org/#user37_anyV44QTvc_0.py

Mini-project # 2 – “Guess the number” game”
http://www.codeskulptor.org/#user38_bvOh0huwfS_8.py
完整阅读

0

Python 如何交互删除集合中的元素?

下面是老师提到的方法,感觉不错就拿到这来了:

rock_group=set(["A", "B", "C", "D"])
#里面有4个陨石
def get_rid_of(rock_group, rock_del):
    remove_set = set([])
    #把要remove的陨石放到这个空集合中
    for i in rock_group:
    #遍历rock_group集合,每次i被集合中的元素赋值,一次一个,直到遍历全部
        if i == rock_del:
            remove_set.add(i)
            #如果是碰撞的陨石,加到remove集合中
    rock_group.difference_update(remove_set)
    #打印rock_group和remove两个集合不同的元素
    
get_rid_of(rock_group,"D")
print rock_group
0

Python – Spaceship 讲解

1. 引用相关的module

import simplegui
import math
import random

2. 全局参量

WIDTH = 800 # 画布的宽
HEIGHT = 600 # 画布的高
score = 0 # 初始分数0
lives = 3 # 3条命
time = 0.5 # 时间为0.5
FRICTION = 0.95 #摩擦系数

完整阅读

0