Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "items": [
- ]
- },
- {
- "items": [
- ]
- },
- {
- "items": [
- ]
- },
- {
- "items": [
- ]
- },
- {
- "items": [
- null
- ]
- }
- OSPF Process 1 with Router ID 1.4.0.1
- Area: 0.0.0.10
- Link State Database
- Type : Router
- Ls id : 1.4.0.1
- Adv rtr : 1.4.0.1
- Ls age : 996
- Len : 48
- Options : ASBR E
- seq# : 8000002f
- chksum : 0xe7f5
- Link count: 2
- * Link ID: 1.16.9.9
- Data : 10.1.155.2
- Link Type: P-2-P
- Metric : 100
- * Link ID: 10.1.155.20
- Data : 255.255.255.252
- Link Type: StubNet
- Metric : 100
- Priority : Low
- Type : Router
- Ls id : 1.16.9.9
- Adv rtr : 1.16.9.9
- Ls age : 392
- Len : 48
- Options : ABR E
- seq# : 8000001e
- chksum : 0x3116
- Link count: 2
- * Link ID: 1.4.0.1
- Data : 10.242.177.21
- Link Type: P-2-P
- Metric : 1
- * Link ID: 10.1.155.20
- Data : 255.255.255.252
- Link Type: StubNet
- Metric : 1
- Priority : Low
- Area: 0.0.0.13
- Link State Database
- Type : Router
- Ls id : 1.4.0.2
- Adv rtr : 1.4.0.2
- Ls age : 1194
- Len : 96
- Options : ASBR E
- seq# : 8001cf7b
- chksum : 0xbfae
- Link count: 6
- * Link ID: 1.4.0.2
- Data : 255.255.255.255
- Link Type: StubNet
- Metric : 0
- Priority : Medium
- * Link ID: 1.4.0.1
- Data : 10.0.0.2
- Link Type: P-2-P
- Metric : 10
- * Link ID: 10.0.0.0
- Data : 255.255.255.252
- Link Type: StubNet
- Metric : 10
- Priority : Low
- * Link ID: 10.40.8.0
- Data : 255.255.255.252
- Link Type: StubNet
- Metric : 100
- Priority : Low
- * Link ID: 19.23.23.15
- Data : 10.40.10.130
- Link Type: P-2-P
- Metric : 10
- * Link ID: 1.4.10.200
- Data : 255.255.255.252
- Link Type: StubNet
- Metric : 10
- Priority : Low
- Type : Router
- Ls id : 100.100.0.10
- Adv rtr : 100.100.0.10
- Ls age : 171
- Len : 84
- Options : ASBR E
- seq# : 8001a292
- chksum : 0x5fa2
- Link count: 5
- * Link ID: 100.100.0.10
- Data : 255.255.255.255
- Link Type: StubNet
- Metric : 12
- Priority : Medium
- * Link ID: 10.10.0.1
- Data : 10.10.10.18
- Link Type: P-2-P
- Metric : 10
- * Link ID: 10.10.10.17
- Data : 255.255.255.255
- Link Type: StubNet
- Metric : 10
- Priority : Medium
- * Link ID: 19.23.23.15
- Data : 10.10.30.30
- Link Type: P-2-P
- Metric : 10
- * Link ID: 10.90.25.30
- Data : 255.255.255.255
- Link Type: StubNet
- Metric : 10
- Priority : Medium
- Type : Router
- Ls id : 10.10.0.1
- Adv rtr : 10.10.0.1
- Ls age : 191
- Len : 96
- Options : ASBR E
- seq# : 80013bcf
- chksum : 0x9871
- Link count: 6
- * Link ID: 10.10.0.1
- Data : 255.255.255.255
- Link Type: StubNet
- Metric : 12
- Priority : Medium
- * Link ID: 15.51.51.14
- Data : 10.10.0.130
- Link Type: P-2-P
- Metric : 10
- * Link ID: 10.10.0.129
- Data : 255.255.255.255
- Link Type: StubNet
- Metric : 10
- Priority : Medium
- * Link ID: 100.100.0.10
- Data : 10.10.10.17
- Link Type: P-2-P
- Metric : 10
- * Link ID: 10.10.10.18
- Data : 255.255.255.255
- Link Type: StubNet
- Metric : 10
- Priority : Medium
- * Link ID: 16.16.16.0
- Data : 255.255.255.252
- Link Type: StubNet
- Metric : 10
- Priority : Low
- Type : Router
- Ls id : 15.51.51.14
- Adv rtr : 15.51.51.14
- Ls age : 2487
- Len : 60
- Options : ASBR ABR E
- seq# : 8000003c
- chksum : 0x1714
- Link count: 3
- * Link ID: 10.242.95.12
- Data : 255.255.255.252
- Link Type: StubNet
- Metric : 1
- Priority : Low
- * Link ID: 10.10.0.1
- Data : 10.10.0.129
- Link Type: P-2-P
- Metric : 1
- * Link ID: 10.10.0.128
- Data : 255.255.255.252
- Link Type: StubNet
- Metric : 1
- Priority : Low
- [
- {
- "items": [
- ]
- },
- {
- "items": [
- ]
- },
- {
- "items": [
- ]
- },
- {
- "Ls age": "996",
- "seq#": "8000002f",
- "items": [
- {
- "Link ID": "1.16.9.9",
- "Link Type": "P-2-P",
- "Metric": "100",
- "Data": "10.1.155.2"
- }
- ],
- "Len": "48",
- "Ls id": "1.4.0.1",
- "chksum": "0xe7f5",
- "Adv rtr": "1.4.0.1",
- "Type": "Router",
- "Options": "ASBR E",
- "Link count": "2"
- },
- {
- "Ls age": "392",
- "seq#": "8000001e",
- "items": [
- {
- "Link ID": "1.4.0.1",
- "Link Type": "P-2-P",
- "Metric": "1",
- "Data": "10.242.177.21"
- }
- ],
- "Len": "48",
- "Ls id": "1.16.9.9",
- "chksum": "0x3116",
- "Adv rtr": "1.16.9.9",
- "Type": "Router",
- "Options": "ABR E",
- "Link count": "2"
- },
- {
- "items": [
- ]
- },
- {
- "Ls age": "1194",
- "seq#": "8001cf7b",
- "items": [
- {
- "Link ID": "1.4.0.2",
- "Link Type": "StubNet",
- "Metric": "0",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- },
- {
- "Link ID": "1.4.0.1",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.0.0.2"
- },
- {
- "Link ID": "10.0.0.0",
- "Link Type": "StubNet",
- "Metric": "10",
- "Data": "255.255.255.252",
- "Priority": "Low"
- },
- {
- "Link ID": "10.40.8.0",
- "Link Type": "StubNet",
- "Metric": "100",
- "Data": "255.255.255.252",
- "Priority": "Low"
- },
- {
- "Link ID": "19.23.23.15",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.40.10.130"
- }
- ],
- "Len": "96",
- "Ls id": "1.4.0.2",
- "chksum": "0xbfae",
- "Adv rtr": "1.4.0.2",
- "Type": "Router",
- "Options": "ASBR E",
- "Link count": "6"
- },
- {
- "items": [
- ]
- },
- {
- "Ls age": "171",
- "seq#": "8001a292",
- "items": [
- {
- "Link ID": "100.100.0.10",
- "Link Type": "StubNet",
- "Metric": "12",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- },
- {
- "Link ID": "10.10.0.1",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.10.10.18"
- },
- {
- "Link ID": "10.10.10.17",
- "Link Type": "StubNet",
- "Metric": "10",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- },
- {
- "Link ID": "19.23.23.15",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.10.30.30"
- }
- ],
- "Len": "84",
- "Ls id": "100.100.0.10",
- "chksum": "0x5fa2",
- "Adv rtr": "100.100.0.10",
- "Type": "Router",
- "Options": "ASBR E",
- "Link count": "5"
- },
- {
- "Ls age": "191",
- "seq#": "80013bcf",
- "items": [
- {
- "Link ID": "10.10.0.1",
- "Link Type": "StubNet",
- "Metric": "12",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- },
- {
- "Link ID": "15.51.51.14",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.10.0.130"
- },
- {
- "Link ID": "10.10.0.129",
- "Link Type": "StubNet",
- "Metric": "10",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- },
- {
- "Link ID": "100.100.0.10",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.10.10.17"
- },
- {
- "Link ID": "10.10.10.18",
- "Link Type": "StubNet",
- "Metric": "10",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- }
- ],
- "Len": "96",
- "Ls id": "10.10.0.1",
- "chksum": "0x9871",
- "Adv rtr": "10.10.0.1",
- "Type": "Router",
- "Options": "ASBR E",
- "Link count": "6"
- },
- {
- "Ls age": "2487",
- "seq#": "8000003c",
- "items": [
- {
- "Link ID": "10.242.95.12",
- "Link Type": "StubNet",
- "Metric": "1",
- "Data": "255.255.255.252",
- "Priority": "Low"
- },
- {
- "Link ID": "10.10.0.1",
- "Link Type": "P-2-P",
- "Metric": "1",
- "Data": "10.10.0.129"
- }
- ],
- "Len": "60",
- "Ls id": "15.51.51.14",
- "chksum": "0x1714",
- "Adv rtr": "15.51.51.14",
- "Type": "Router",
- "Options": "ASBR ABR E",
- "Link count": "3"
- },
- {
- "items": [
- ]
- },
- {
- "items": [
- null
- ]
- }
- ]
- # To remove specific line/string
- filename = 'raw1.txt'
- with open(filename, 'r') as fin:
- lines = fin.readlines()
- with open('clean.txt', 'w') as fout:
- for line in lines:
- if not re.match(r"s+(Area|OSPF|Link State)", line):
- fout.write(line)
- #To return clean file onto json structure
- results = []
- group = {}
- group['items'] = []
- subgroup = None
- with open('clean.txt') as infile:
- for line in infile:
- if not line.strip():
- results.append(group)
- group = {}
- group['items'] = []
- subgroup = None
- elif not line.startswith(' '):
- key, val = line.split(':')
- key = key.strip()
- val = val.strip()
- group[key] = val
- else:
- if '*' in line:
- if subgroup:
- group['items'].append(subgroup)
- subgroup = {}
- key, val = line.split(':')
- key = key.replace('*', '').strip()
- val = val.strip()
- subgroup[key] = val
- group['items'].append(subgroup)
- results.append(group)
- print(json.dumps(results, indent=2))
- with open('myjson.json', 'w') as json_file:
- json.dump(results, json_file)
- [
- {
- "Ls age": "996",
- "seq#": "8000002f",
- "items": [
- {
- "Link ID": "1.16.9.9",
- "Link Type": "P-2-P",
- "Metric": "100",
- "Data": "10.1.155.2"
- }
- ],
- "Len": "48",
- "Ls id": "1.4.0.1",
- "chksum": "0xe7f5",
- "Adv rtr": "1.4.0.1",
- "Type": "Router",
- "Options": "ASBR E",
- "Link count": "2"
- },
- {
- "Ls age": "392",
- "seq#": "8000001e",
- "items": [
- {
- "Link ID": "1.4.0.1",
- "Link Type": "P-2-P",
- "Metric": "1",
- "Data": "10.242.177.21"
- }
- ],
- "Len": "48",
- "Ls id": "1.16.9.9",
- "chksum": "0x3116",
- "Adv rtr": "1.16.9.9",
- "Type": "Router",
- "Options": "ABR E",
- "Link count": "2"
- },
- {
- "Ls age": "1194",
- "seq#": "8001cf7b",
- "items": [
- {
- "Link ID": "1.4.0.2",
- "Link Type": "StubNet",
- "Metric": "0",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- },
- {
- "Link ID": "1.4.0.1",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.0.0.2"
- },
- {
- "Link ID": "10.0.0.0",
- "Link Type": "StubNet",
- "Metric": "10",
- "Data": "255.255.255.252",
- "Priority": "Low"
- },
- {
- "Link ID": "10.40.8.0",
- "Link Type": "StubNet",
- "Metric": "100",
- "Data": "255.255.255.252",
- "Priority": "Low"
- },
- {
- "Link ID": "19.23.23.15",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.40.10.130"
- }
- ],
- "Len": "96",
- "Ls id": "1.4.0.2",
- "chksum": "0xbfae",
- "Adv rtr": "1.4.0.2",
- "Type": "Router",
- "Options": "ASBR E",
- "Link count": "6"
- },
- {
- "Ls age": "171",
- "seq#": "8001a292",
- "items": [
- {
- "Link ID": "100.100.0.10",
- "Link Type": "StubNet",
- "Metric": "12",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- },
- {
- "Link ID": "10.10.0.1",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.10.10.18"
- },
- {
- "Link ID": "10.10.10.17",
- "Link Type": "StubNet",
- "Metric": "10",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- },
- {
- "Link ID": "19.23.23.15",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.10.30.30"
- }
- ],
- "Len": "84",
- "Ls id": "100.100.0.10",
- "chksum": "0x5fa2",
- "Adv rtr": "100.100.0.10",
- "Type": "Router",
- "Options": "ASBR E",
- "Link count": "5"
- },
- {
- "Ls age": "191",
- "seq#": "80013bcf",
- "items": [
- {
- "Link ID": "10.10.0.1",
- "Link Type": "StubNet",
- "Metric": "12",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- },
- {
- "Link ID": "15.51.51.14",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.10.0.130"
- },
- {
- "Link ID": "10.10.0.129",
- "Link Type": "StubNet",
- "Metric": "10",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- },
- {
- "Link ID": "100.100.0.10",
- "Link Type": "P-2-P",
- "Metric": "10",
- "Data": "10.10.10.17"
- },
- {
- "Link ID": "10.10.10.18",
- "Link Type": "StubNet",
- "Metric": "10",
- "Data": "255.255.255.255",
- "Priority": "Medium"
- }
- ],
- "Len": "96",
- "Ls id": "10.10.0.1",
- "chksum": "0x9871",
- "Adv rtr": "10.10.0.1",
- "Type": "Router",
- "Options": "ASBR E",
- "Link count": "6"
- },
- {
- "Ls age": "2487",
- "seq#": "8000003c",
- "items": [
- {
- "Link ID": "10.242.95.12",
- "Link Type": "StubNet",
- "Metric": "1",
- "Data": "255.255.255.252",
- "Priority": "Low"
- },
- {
- "Link ID": "10.10.0.1",
- "Link Type": "P-2-P",
- "Metric": "1",
- "Data": "10.10.0.129"
- }
- ],
- "Len": "60",
- "Ls id": "15.51.51.14",
- "chksum": "0x1714",
- "Adv rtr": "15.51.51.14",
- "Type": "Router",
- "Options": "ASBR ABR E",
- "Link count": "3"
- },
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement