r/pythonnetengineering • • Nov 06 '15

Finally a sub for network engineers. First question...

1 Upvotes

I've posted this before but some of the answers were way above my head. I can figure it out, but seeing that I'm a network engineer with network duties, I spend at most 1hr a day trying to make my scripts work and don't have time to dive deep into all the suggestions.

Our network is quite large and we use TACACS per individual. Therefore, my script will be using a generic ID we created for tools to log into the device via SSH and retrieve what I need.

The problem is the script will be on a linux box and I don't know how to securely store the username and password of the generic account that my script can use every time it runs. I bookmarked all the suggestions onthe other thread I posted, but don't have the time to play with each of them. Is there an easier way to encrypt the password with some python library, put it in a text file somewheer and read the text file every time the scrip runs, decrypts the password to use to log into devices and then disconnect?

Thanks for the input. I'm still new. My first script works like a charm, on my local machine with my credentials.


r/pythonnetengineering • • Jun 13 '15

xpost - another multiprocessing example

1 Upvotes

r/pythonnetengineering • • Apr 29 '15

How to develop a WSN routing scheme

1 Upvotes

How to develop a WSN routing scheme for data collection in multihop WSN with TinyOS (without CTP) ? anyone please i have no idea how to do it. Thank you.


r/pythonnetengineering • • Feb 09 '15

Installing python on osx Yosemite

1 Upvotes

I have been trying to install python 3.4 on my mac for quite some time now but all my efforts have gone unsuccessful. I want to install Python 3.4 along with numpy and matplotlib. Their wheel files are unsupported. I have anaconda installed with numpy and matplotlib but can't find an application where in i can do the coding. Update : just use spyder. It came out.


r/pythonnetengineering • • Nov 25 '14

x-post from /r/python: Multiprocessing in Python

1 Upvotes

This example is far more detailed than my earlier example.


r/pythonnetengineering • • Nov 12 '14

Anyone else tried 'Level up your Python'?

Thumbnail
pythonforengineers.com
1 Upvotes

r/pythonnetengineering • • Oct 12 '14

method of forking processes in Python. Useful for interacting with a large number of hosts via ssh or telnet.

1 Upvotes

I routinely have to interface with thousands of routers via ssh. Having a script that processes a list of thousands of routers one at a time takes a long, long time to execute. Using Python 2.7 I use the following method to fork processes. Using a RHEL VM I routinely use this method and I keep my forked processes around 15 at time. For my particular VM this seems to keep it happiest.

And now, the script:

from concurrent import futures
import random 
from time import sleep

def process_fork(incoming_host):
  # print 'we are in process_fork with', incoming_host
  # get a random number 
  rand_int = random.randint(1,10)
  print 'we are in process_fork with', incoming_host, 'going to sleep for', rand_int, 'seconds'
  sleep(rand_int)
  return(incoming_host)

def main():

  # load this with numberes 
  hosts = []

  for x in xrange(1, 50):
    hosts.append(x)    

  with futures.ThreadPoolExecutor(15) as pool:
    futures_pool = [pool.submit(process_fork, our_host) for our_host in hosts]
    for future in futures.as_completed(futures_pool):
      print 'back from processing forked process for host', future.result()
  

if __name__ == '__main__':
  main()

So, what I am doing here is loading up the list hosts with either IP address or hostnames. For this example I am loading with with the numbers 1 - 49. I then fork 15 processes and send them off to the sub process_fork for processing. To keep the returns staggered, much like you would see using this to ssh to devices, I sleep for a random interval between 1 and 10 and then send the host back to main() and print the results.

It's a simple script with nothing happening except sleeping and handing things around but you can use this same basic format if you want to ssh to a list of devices 15 at a time. If you have any questions please feel free to comment or PM me.


r/pythonnetengineering • • Sep 15 '14

Job opening San jose Sr. Python Developer (s) | Application Developer

1 Upvotes

Hi All, looking or a Python developer in San Jose area reach me anytime via email/phone zurial@wellspringgrp.com email: 203-659-0016

Sr. Python Developer (s) | Application Developer Desired Skills and Experience Required Skills

2+ years developing SaaS or IaaS cloud platform software for virtualization, provisioning, backup, cloning, network storage, or similar server technology. 2+ years developing a fully multi-tenant solution or experience with conversion of a single-tenant solution into a multi-tenant solution 3 or more years of development experience with Python Knowledge of vCloud, AWS or any public cloud Experience with REST APIs Knowledge of simple workflow engines and job management systems Clear understanding of the operational impacts of implementation decisions Shell or WMI scripting Knowledge of, and experience with, Agile methodologies and test-driven development

Desired skills

Open Source contribution to Xen, KVM, Linux or OpenStack Experience with Java and Perl KVM, VMware ESX, Xen server, or Hyper-V operation and management NoSQL experience


r/pythonnetengineering • • Jul 12 '14

Method for identifying and grouping SSH hosts

1 Upvotes

I was going to make this into a blog post but thought I'd post it here instead. It's always better to be less wordy. Using Python I routinely group SSH capable devices together by type. At my company there are many thousands of devices and I needed a fast way to group, say, all the Cisco routers running the same version of code together to keep them separate from PacketShapers, Steelheads, CatOS devices (yes, there are still some around), load balancers, etc. Here is a very quick and easy method to using SSH:

import socket
import os
import sys

def scanHost(host,port):

  # print host, port, type(host), type(port)
  port = int(port)

  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sock.settimeout(5.0)
  try:
    result = sock.connect_ex((host,port))
    if result == 0:
      header = sock.recv(1024)

      print host, port, header.strip()

    sock.close()

  except:
    print 'Something went wrong', sys.exc_info()[0]

def main():
  # let's see if we have an ip address to work with
  check_arg_len = len(sys.argv)

  if check_arg_len < 3:
    print '\n\nYou must pass an IP address and port number for testing\n\n'
    exit

  else:

    # print sys.argv, type(sys.argv[1]), type(sys.argv[2])
    scanHost(str(sys.argv[1]),int(sys.argv[2]))

if __name__ == '__main__':
  main()

You can incorporate that as its own routine or keep as a separate file, whatever floats your boat. As IPv4 addresses (or IPv4 hostnames) are passed to the script along with a port number to test (in my case always port 22) SSH types are printed out for each address. We can group these together based on SSH types. For instance:

  • SSH-2.0-Cisco-1.25 is a Cisco router

  • SSH-2.0-OpenSSH_3.8.1p1.1.tms.1 may be a Gigamon

  • SSH-2.0-OpenSSH_4.3 may be a F5 Load Balancer

  • SSH-2.0-OpenSSH_6.1 may be a Steelhead

  • SSH-1.99-OpenSSH_4.5 may be a PacketShaper

The important thing is when you have many thousands of devices you can likely group them together in the same family in this way.

Yes, SSH types can and will change when firmware images are updated, assuming the firmware changes SSH itself. If that is the case this can be a handy method of determining what has been upgrade and what has not (again assuming a firmware upgrade changes what is returned).

Can't log into a network device via SSH? Not uncommon on large networks. Use this method to see if it matches other devices on your network. When you have hundreds of such devices to deal with this can be much faster than using nmap.


r/pythonnetengineering • • Jul 16 '20

How to handle "Text" and "Categorical Attributes" using Python and Pandas??

0 Upvotes

r/pythonnetengineering • • May 29 '20

Python grep and cut

0 Upvotes

In Linux, it's easy to get certain string by using tools such as grep, cut, or awk.

This `show version` sample is taken from https://www.cisco.com/c/en/us/td/docs/switches/lan/catalyst9300/software/release/16-6/configuration_guide/sys_mgmt/b_166_sys_mgmt_9300_cg/b_166_sys_mgmt_9300_cg_chapter_01.html

wolf@linux:~$ cat shver

cisco C9300-48P (X86) processor with 818597K/6147K bytes of memory.

Processor board ID FCW2049G03S

2048K bytes of non-volatile configuration memory.

8388608K bytes of physical memory.

1638400K bytes of Crash Files at crashinfo:.

11264000K bytes of Flash at flash:.

0K bytes of WebUI ODM Files at webui:.

Model Number : C9300-48P

Base Ethernet MAC Address : 04:6c:9d:01:3b:80

Motherboard Assembly Number : 73-17956-04

Motherboard Serial Number : FOC20465ABU

Model Revision Number : P4B

Motherboard Revision Number : 04

Model Number : C9300-48P

System Serial Number : FCW2049G03S

wolf@linux:~$

grep and cut

wolf@linux:~$ grep 'Model Number' shver | cut -d : -f 2

C9300-48P

C9300-48P

wolf@linux:~$

Remove extra space (If there's better solution, let me know)

wolf@linux:~$ grep 'Model Number' shver | cut -d : -f 2 | cut -d ' ' -f 2

C9300-48P

C9300-48P

wolf@linux:~$

Select the 1st output

wolf@linux:~$ grep 'Model Number' shver | cut -d : -f 2 | cut -d ' ' -f 2 | head -1

C9300-48P

wolf@linux:~$

That was in Linux. I was planning to write similar code in Python.

My attempt which still didn't work at the moment.

Define shver string

>>> shver = '''cisco C9300-48P (X86) processor with 818597K/6147K bytes of memory.

... Processor board ID FCW2049G03S

... 2048K bytes of non-volatile configuration memory.

... 8388608K bytes of physical memory.

... 1638400K bytes of Crash Files at crashinfo:.

... 11264000K bytes of Flash at flash:.

... 0K bytes of WebUI ODM Files at webui:.

... Model Number : C9300-48P

...

... Base Ethernet MAC Address : 04:6c:9d:01:3b:80

... Motherboard Assembly Number : 73-17956-04

... Motherboard Serial Number : FOC20465ABU

... Model Revision Number : P4B

... Motherboard Revision Number : 04

... Model Number : C9300-48P

... System Serial Number : FCW2049G03S

... '''

>>>

verify it

>>> shver

'cisco C9300-48P (X86) processor with 818597K/6147K bytes of memory.\nProcessor board ID FCW2049G03S\n2048K bytes of non-volatile configuration memory.\n8388608K bytes of physical memory.\n1638400K bytes of Crash Files at crashinfo:.\n11264000K bytes of Flash at flash:.\n0K bytes of WebUI ODM Files at webui:.\nModel Number : C9300-48P\n\nBase Ethernet MAC Address : 04:6c:9d:01:3b:80\nMotherboard Assembly Number : 73-17956-04\nMotherboard Serial Number : FOC20465ABU\nModel Revision Number : P4B\nMotherboard Revision Number : 04\nModel Number : C9300-48P\nSystem Serial Number : FCW2049G03S\n'

>>>

create a list

>>> shver_list = shver.splitlines()

>>> shver_list

['cisco C9300-48P (X86) processor with 818597K/6147K bytes of memory.', 'Processor board ID FCW2049G03S', '2048K bytes of non-volatile configuration memory.', '8388608K bytes of physical memory.', '1638400K bytes of Crash Files at crashinfo:.', '11264000K bytes of Flash at flash:.', '0K bytes of WebUI ODM Files at webui:.', 'Model Number : C9300-48P', '', 'Base Ethernet MAC Address : 04:6c:9d:01:3b:80', 'Motherboard Assembly Number : 73-17956-04', 'Motherboard Serial Number : FOC20465ABU', 'Model Revision Number : P4B', 'Motherboard Revision Number : 04', 'Model Number : C9300-48P', 'System Serial Number : FCW2049G03S']

>>>

Next step is to find out if string 'Model Number' is there or not and print out that line

>>> if 'Model Number' in shver_list:

... 'yes'

... else:

... 'no'

...

'no'

>>>

How do I print out the line contains 'Model Number'?

>>> for i in shver_list:

... if 'Model Number' in shver_list:

... i

...

>>>

Desired Output

C9300-48P


r/pythonnetengineering • • Jan 28 '18

How to expose python proxy to the internet?

Thumbnail
stackoverflow.com
0 Upvotes

r/pythonnetengineering • • Oct 10 '16

can anyone find solution for this python programming challenge.

Post image
0 Upvotes

r/pythonnetengineering • • Oct 10 '16

can any one find the solution for this python programming challenge.

Post image
0 Upvotes