Skip to content

Instantly share code, notes, and snippets.

View kubsoo's full-sized avatar

Jakub Mazurkiewicz kubsoo

View GitHub Profile
@kubsoo
kubsoo / http2sms.py
Last active April 24, 2018 07:30
HTTP SMS gateway in Python for Cisco ISE 2.X using gnokii (with USB dongle with SIM-card)
#!/usr/bin/python
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
import urllib,os,io
PORT_NUMBER = 80 #http port listening on
#Decode URL path from ISE GET request
def decode_path(path):
number=path.split("&to=")[1].split("&message=")[0]
message=path.split("&message=")[1].replace('+',' ')
@kubsoo
kubsoo / upgrade_cisco.py
Created April 4, 2018 12:14
Python script to upgrade ios on cisco devices. Script checks md5 checksum, upload ios, insert boot system command, backup run config and reloads switch.
#!/usr/bin/python
import netmiko
from netmiko import SCPConn
import os,sys,commands,re
def check_md5(filename):
command = 'md5sum '+filename
o = commands.getoutput(command)
@kubsoo
kubsoo / del_endpoint.py
Created March 28, 2018 08:33
Python script which removes endpoints stored in endpoint.txt from Cisco ISE using Rest API.
#!/usr/bin/python
import requests, re
headers = {
'Accept': 'application/vnd.com.cisco.ise.identity.endpoint.1.0+xml',
}
file = open("endpoint.txt","r") ### file which contains list of endpoints to delete
a = file.read().splitlines()
@kubsoo
kubsoo / config_palo.py
Last active March 19, 2018 21:11
Python script which adds security rule on Palo Alto firewalls using REST API.
#!/usr/bin/python
import requests, getpass, re
## list of firewalls
firewalls_ip = [
'192.168.0.201',
'192.168.0.202',
'192.168.0.203',
]
@kubsoo
kubsoo / config_cisco.py
Last active February 12, 2018 20:04
Python script which saves configuration into cisco ios devices using ssh. Script takes configuration from text file.
#!/usr/bin/python
from netmiko import ConnectHandler
### function which writes commands into device
def set_cmd(ip, username, password,commands):
# establish a connection to the device
ssh_connection = ConnectHandler(
device_type='cisco_ios',
ip=ip,
@kubsoo
kubsoo / palo_export_config.py
Created January 11, 2018 20:55
Python script which exports running config from Palo Alto firewalls and save it into xml files on disk.
#!/usr/bin/python
import requests, datetime
from lxml import etree
### list with firewalls_ip
firewalls_ip = [
'192.168.0.201',
'192.168.0.202',
'192.168.0.203'
@kubsoo
kubsoo / backup_config.py
Last active April 8, 2022 10:09
Python script which uses napalm library to backup configuration for cisco ios devices.
#!/usr/bin/python
import napalm, re, datetime, os
path = os.getcwd()
try:
os.stat(path+'/backup_config')
except:
os.mkdir(path+'/backup_config')
@kubsoo
kubsoo / nmap_cisco.py
Created January 8, 2018 09:07
Script which scans subnet for cisco ios devices and returns dictionary with ip addresses and ios connection method (ssh or telnet)
#!/usr/bin/python
import nmap, time
start_time = time.time()
def scan_subnet_for_ssh_cisco(subnet):
### Function scanning subnet with nmap (ports tcp/22, tcp/23) and finding cisco ios devices
### returning dictionary with ip address and connection method (telnet, ssh)
@kubsoo
kubsoo / update_kernel.py
Created January 7, 2018 21:09
Python script which automatically updates kernel to newest available version in http://kernel.ubuntu.com/~kernel-ppa/mainline/. Scripts works for Ubuntu and Debian systems.
#!/usr/bin/python
import os,commands,requests, re
get_ver = 'uname -r'
get_arch = 'dpkg --print-architecture'
url = 'http://kernel.ubuntu.com/~kernel-ppa/mainline/'
#Check processor architecture
status,arch = commands.getstatusoutput(get_arch)
@kubsoo
kubsoo / sh_version.py
Last active February 1, 2023 12:42
Python script which connects to cisco routers (using netmiko library) through ssh and get informations (hostname,model,uptime,version,ios,serial) from sh version command
#!/usr/bin/python
from netmiko import ConnectHandler
import re
#here is list of cisco routers ip addresses
ip_list = ['192.168.174.101','192.168.174.102','192.168.174.103','192.168.174.104','192.168.174.105','192.168.174.106']
#list where informations will be stored
devices = []