Skip to content

Instantly share code, notes, and snippets.

@spdkils
spdkils / ACEparse.py
Last active September 23, 2017 03:45
Dissect Cisco ACEs for flipping for whatever...
# flip ace
import re
def ace_elements(ace):
ace = ace.strip()
'''Dissect ACE statement into it's parts.
returns and array of each part as follows
[action protocol src_address src_ports dst_address dst_ports established]
Any empty element returns None. For example:
# Name-Port Mappings Cisco
tcp_ports = {
'bgp': '179',
'chargen': '19',
'cmd': '514',
'daytime': '13',
'discard': '9',
'domain': '53',
'echo': '7',
# Sexy Lexi
import collections
import re
import acltests
import aceNamePort
from tkinter import *
root = Tk()
Token = collections.namedtuple('Token', ['typ', 'value', 'line', 'column'])
@spdkils
spdkils / aclv2.g4
Created October 3, 2017 05:16
Cisco ACLs v2
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
grammar aclv2;
acl : ace+ EOF ;
ace : remarks*? action ops ;
@spdkils
spdkils / aclv3.g4
Last active October 5, 2017 04:51
antlr4 Cisco ACL parser 3rd version
grammar aclv3;
acl : ace+ EOF ;
ace : action ops ;
action : REMARK
| ( PERMIT ( NAMED | NUM ) source dest )
| ( DENY ( NAMED | NUM ) source dest )
;
source : ( ANY | HOST ADDRESS | ADDRESS ( MASK | ADDRESS ) ) srcports? ;
dest : (ANY | HOST ADDRESS | ADDRESS ( MASK | ADDRESS ) ) dstports? ;
@spdkils
spdkils / aclFLip.py
Created January 16, 2018 08:06
Ugly Function to flip ACE statements. (Usable to see if outbound has properly inverted statements.
import re
def flipACE(ace: str) -> list:
search = r'(?:host \d+\.\d+\.\d+\.\d+|\d+\.\d+\.\d+\.\d+ \d+\.\d+\.\d+\.\d+|any)'
endofline = r'(?:established|log-input|log|$)'
remark = r'^ ?remark'
if re.search(remark, ace):
return ace.split()
if re.search(' reflect ', ace):
@spdkils
spdkils / show_cdp_neighbors_detail.tpl
Last active January 15, 2019 22:24
TextFSM showcdpneighbordetail
Value REMOTE_DEVICE_ID (.*)
Value List REMOTE_ENTRY_ADDRESSES (.*)
Value REMOTE_PLATFORM ([^,]+)
Value REMOTE_SYSTEM_CAPAB (.*)
Value LOCAL_INTERFACE ([^,]+)
Value REMOTE_PORT (.*)
Value REMOTE_HOLDTIME (\d+)
Value REMOTE_SYSTEM_VERSION (.+)
Value REMOTE_CDP_VERSION (.+)
Value REMOTE_DUPLEX (.+)
@spdkils
spdkils / subnets_collapse.py
Created January 17, 2019 16:19
subnet squeeze
from typing import List
import ipaddress
lst = ['10.10.20.0/24',
'10.10.30.0/25',
'10.10.30.128/25',
'10.10.31.0/24',
'10.10.32.0/24'
]
@spdkils
spdkils / test_file.gcode
Created August 23, 2022 23:21
Test Gcode
;-------------------------------Cut file parameters------------------------
; Input file name : reorder.svg
; File rotation : 0 File scale : 1
; Material name : Glass, Soda Lime
; Material thickness : 3.3 mm
; Cut path : Centerline
; Cut quality : roughRate
; Raw Material width : 130.00mm
; Raw Material height : 100.00mm
;-------------------------------Do Not modify the Gcode file---------------
@spdkils
spdkils / win_aio_copy_file.py
Last active February 4, 2024 00:35
No dependecy windows actual async file copies?
import asyncio
import ctypes
from ctypes import windll, wintypes
from pathlib import Path
# Define necessary constants and structures
FILE_READ_DATA = 0x1
FILE_READ_SHARED = 0x1
FILE_WRITE_DATA = 0x2
CREATE_ALWAYS = 0x2