Python Scripts: Difference between revisions

Content added Content deleted
Line 12: Line 12:
sys.stdout.flush()
sys.stdout.flush()


== Regex ==
*Extract a particular value(like 10.5, 100.0):
value = re.findall(r'([0-9]{3}.[0-9]|[0-9]{2}.[0-9]|[0-9].[0-9])(?=\sid)', output)
# Print all matches
print value
# Print 2nd Match
print value[1]


== Arrays ==


*Using Array
x = [1,2,3,4,5]
for i in range(5):
print x[i]

*Append to Array
f = []
for i in range(30):
f.append(i)
print f

== Pause ==

import time
time.sleep(5)

== EasySNMP ==
{{notice|This snippet needs more testing.}}
sudo apt-get install libsnmp-dev snmp-mibs-downloader
sudo apt-get install gcc python-dev
sudo pip install easysnmp

from easysnmp import snmp_get
snmp_get('.1.3.6.1.4.1.2021.10.1.3.1', hostname='10.107.88.93', community='public', version=2)


= Calculator =
= Calculator =