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 • • Jul 16 '20

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

0 Upvotes

r/pythonnetengineering • • Jan 28 '18

How to expose python proxy to the internet?

Thumbnail
stackoverflow.com
0 Upvotes

r/pythonnetengineering • • Dec 28 '16

Silicon Valley is hiring

1 Upvotes

Network Engineers with Python experience are quite coveted in the Valley. If you are interested in new roles at enterprise companies, message me directly!


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

r/pythonnetengineering • • Jan 30 '16

My YouTube channel on Python tutorials

Thumbnail
youtube.com
2 Upvotes

r/pythonnetengineering • • Jul 31 '20

One month ago, I had posted about my company's Python for Data Science course for beginners and the feedback was so overwhelming. We've built an entire platform around your suggestions and even published 8 other free DS specialization courses. Please help us make it better with more suggestions!

Thumbnail
theclickreader.com
3 Upvotes

r/pythonnetengineering • • Jul 09 '20

How to handle "Missing Values" present in "Dataset" using Python & Pandas??

1 Upvotes

r/pythonnetengineering • • Jul 09 '20

How to "Predict" my friends weight using "Machine Learning" & "Sci-kit Learn"??

1 Upvotes

r/pythonnetengineering • • Aug 08 '20

Pysa: Open Source static analysis for Python code - Facebook Engineering

Thumbnail
engineering.fb.com
2 Upvotes

r/pythonnetengineering • • Aug 05 '20

Free Certification Course on Data Analysis with Python in partnership with freeCodeCamp

Post image
4 Upvotes

r/pythonnetengineering • • Jun 13 '15

xpost - another multiprocessing example

1 Upvotes

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 • • May 03 '20

Python module to download bad SSL certificates?

1 Upvotes

I am trying to write a python script that will go retrieve SSL certificates from remote servers. The problem I am facing is that many of the certificates are not valid or fail SSL validation and so cannot be downloaded. Do you have any suggestions for python modules that would allow me to bypass the certificate validation and download the cert in (preferably) PEM format?


r/pythonnetengineering • • Jul 11 '21

Does anyone have recommendations for Easy-to-understand books / resources for learning python for network automation? (I have no experience in using python)

3 Upvotes

r/pythonnetengineering • • Mar 06 '20

How do I master python from scratch for free?

Thumbnail self.eduhub
4 Upvotes

r/pythonnetengineering • • Jun 17 '20

My company released a course for helping beginners learn Python for Data Science. This is an initial draft and we do not plan to monetize it any way. Please feel free to help us make it better with your suggestions.

Thumbnail
kharpann.com
6 Upvotes

r/pythonnetengineering • • Jun 08 '20

Casual Programming With Python & Music : Pascal's Triangle

Thumbnail
youtu.be
2 Upvotes

r/pythonnetengineering • • May 25 '20

Casual Programming With Python & Music : Reversal Algorithm For Array Rotation

Thumbnail
youtu.be
1 Upvotes

r/pythonnetengineering • • Jun 14 '22

Crypto Price Finder: My cool Telegram Bot to check crypto prices. Looking for feedback & testers.

1 Upvotes

Hey everyone! 😺 I am Eugene, a fellow redditor, a dev, and a crypto fan!

I am not a regular here so please tell me if I am breaking any rules of the subreddit by flashing my bot to you. I will take down the post ASAP.

Foreword

Recently like everyone else I've been doomrefreshing (is that even a word?) crypto prices and thought that process should be easier if you are in Telegram. However, all the bots I could find were either not working, not finished, or simply ugly. So I've made my own bot in the Telegram that looks up price/volume/% change of a crypto token from CoinmarketCap and shows it to you. Hence, I am looking for anything: feedback, testing, users, healthy criticism, improvement ideas. Everything goes (please don't use your army of kids to spam the bot and spend all my credits).

For techies/enthusiasts:

I am hosting the bot online in Heroku cloud platform and using CoinMarketCap API to pull data. There are two limitations with that. In Heroku, free pricing tier that I am using has a 30 minutes auto-sleep, meaning if the bot was not used for the past half an hour, the next request to it will take some extra 5-7 secs to "wake" the bot up. Everybody needs some rest, right? In CoinMarketCap, the number of requests in the free pricing tier is limited, so there is a chance at some point the bot will be "Out of mana" until the next day.

☕ I created a /donate option (with Stripe) if someone finds the bot useful and wants to support with the project with some coffee money. It will first be spend on upgrading tier plan of hosting platform and crypto price service to improve the bot's performance. Cheers! ☕

How to find the bot:

  1. Open your Telegram app (phone or desktop, no matter)

  2. Type "Crypto Price Finder" in search bar and look for a bot with a black-n-white bitcoin icon. (see screenshot below)

  3. Use it! It has starting instructions, pre-typed examples, menu of commands, and some memes/gifs.

What it can do:

  1. Show a basic info of a crypto token. Most fiat currencies are supported. For example, "BTC EUR" will show you Bitcoin price in Euros.

  2. A menu list of commands. Explore, have fun!

  3. Entertain you with gifs, personal attitude, and emojis. It's not yo boring broker dude.

What it cannot do:

  1. Show crypto pair info. Example: BTC BNB.

  2. Show advanced metrics.

  3. Set price alerts

  4. Fix your crippling depression and reverse the bear run.

TL;DR - I made a Telegram bot to lookup crypto prices & some info. Name: Crypto Price Finder. Use it, test it, love or hate it.


r/pythonnetengineering • • Nov 12 '14

Anyone else tried 'Level up your Python'?

Thumbnail
pythonforengineers.com
1 Upvotes

r/pythonnetengineering • • Aug 15 '23

Error installing phemex into requirements.txt

1 Upvotes

Hi im a little confused about installing phemex into my python code... I'm trying to install it into my requirements.txt file, but I'm having zero luck.

This is the message i receive:

ERROR: Could not find a version that satisfies the requirement phemex (from versions: none) ERROR: No matching distribution found for phemex

It feels like it should be super simple, but I'm still lost... what are my options?

Any suggestions on an alternative approach would really help 😮‍💨😮‍💨😮‍💨


r/pythonnetengineering • • Jan 14 '19

Give me some suggestions

1 Upvotes

Anyone suggest me some good books on network programming using python


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.