novice20 17 Junior Poster

@richieking:

Why do u say so??? I have been following the advices and found some of them useful...Well, in the previous thread, I had replied to your post with my problem and you didn't bother to reply...well thanx for the advices

@grib:

I want to do it from inside a script, neither urllib.urlopen nor the built in open helped me

thanks for your reply too...

novice20 17 Junior Poster

hi all,

can anyone tell me how to open a folder on a remote machine connected on same LAN.

I need to open a folder in the form "\\remote_machine\folder1\folder2\folder3"

novice20 17 Junior Poster

Start reading python ftp lib.

Connect via ftp then you get access to the remote system.
bingo ;)

@richie.......

connecting via FTP requires, ftp daemon running on the server to which we want to connect. I need help regarding urllib .Pls anyone.....

novice20 17 Junior Poster

any body pls help me....it is blocking me n I am getting frustrated :( :( :(

hi all,

Isnt anybody of any help?:(

novice20 17 Junior Poster

and forgot to mention, bbb is a folder

any body pls help me....it is blocking me n I am getting frustrated :( :( :(

novice20 17 Junior Poster

How is a URL specified within a call for urllib2.urlopen(). I want to specify something like 192.168.5.140/XXX_yyy/ZZZ_yyy/bbb

and forgot to mention, bbb is a folder

novice20 17 Junior Poster

tonyjv,
I read that urllib2 is supported on python 3. I want something that is portable, i.e., the one which can run on any machine which has a basic python version. I want it because, the code shouldnt require a version update, if it has to be run on different machines.

Pla help me out

How is a URL specified within a call for urllib2.urlopen(). I want to specify something like 192.168.5.140/XXX_yyy/ZZZ_yyy/bbb

novice20 17 Junior Poster

check out urllib2.urlopen.

tonyjv,
I read that urllib2 is supported on python 3. I want something that is portable, i.e., the one which can run on any machine which has a basic python version. I want it because, the code shouldnt require a version update, if it has to be run on different machines.

Pla help me out

novice20 17 Junior Poster

check out urllib2.urlopen.

tonyjv,
I read that urllib2 is supported on python 2.3. I want something that is portable, i.e., the one which can run on any machine which has a basic python version. I want it because, the code shouldnt require a version update, if it has to be run on different machines.

Pla help me out

novice20 17 Junior Poster

hi all,
can anyone tell me hoe to open a file from one machine, when the file is present on a remote machine, specifying it's IP address?

novice20 17 Junior Poster

How to validate an IP Address using python?

It should reject the shorter addresses such as 192.168 instead of padding the rest of the bits the address with 0s

novice20 17 Junior Poster

when the parser is populated with options using optparse,
in a case where an option say 'ip' is to be used twice, I get an OptionConflictError.


when the conflict handler was set to "resolve" as suggested in http://docs.python.org/library/optparse.html , it resolves the situation by removing '-ip' from the earlier options list of option strings.


I don't want this to happen. I want the option '-ip' to be used twice in my command line arguments.

how can this be acheived, without encountering OptionConflictError??

novice20 17 Junior Poster

There are many possible improvements in your code. Write functions and classes !

@Grib: thanks a lot...I'll consider it

novice20 17 Junior Poster

can anyone show a small sample of how optparse module can be used to parse a command line arguement?

the command line is somewhat like:

<scriptname> -ip<ip address> -opt1/opt2

novice20 17 Junior Poster

I realized it was not a problem with my client code, but a problem with the 'single binary image'(file to be uploaded) I created:P]. Now it's working fine

novice20 17 Junior Poster

It's difficult to help you without the faulty client code.

here is my faulty client code...

..................
................
...................

#-- prompt the user for file location


retry=1
while(retry<5):
try:
logging.info("Enter the file location")
file = raw_input()
logging.info(file)
filename= os.path.basename(file)
retry+=1
f=open(filename,"rb")
logging.info("File present")
flag=0
break
except Exception,e:
logging.debug(e)
logging.info("Invalid path, Try again")
flag=1
if flag==1:
logging.info("FILE NOT PRESENT")
exit(1)
else:
pass
#-- upload the file

try:
subprocess.call(,shell=True)
uploadSuccess=1
#logging.info("UPLOAD IN PROGRESS")

except Exception,e:
logging.info(e)
#logging.info("UPLOAD FAILED")
exit(1)


#-- Check whether card has USB interface (i.e., whether it is a 4501 card)
from pysnmp.entity.rfc3413.oneliner import cmdgen
errorIndication,errorStatus,errorIndex,varBinds = cmdgen.CommandGenerator().getCmd( cmdgen.CommunityData('xxx', 'yyy', 1), cmdgen.UdpTransportTarget(('192.168.155.164',161 )),(1,3,6,1,4,1,18489,1,2,1,4,6,3,0))

logging.info("ERROR ON GET:")
logging.info(errorIndication)

logging.info("ERROR STATUS:")
logging.info(errorStatus)
logging.info(varBinds)

value = varBinds[0][1]
#check the first four chars in the tuple
if value[:4]== '4501':
logging.info("USB KEY SUPPORT PRESENT")
USBKey=1
else:
logging.info("USB KEY SUPPORT NOT PRESENT")
exit(1)

#-- query on ccmSDIDUKeyStatus

try:
errorIndication, errorStatus, errorIndex, varBinds1 = cmdgen.CommandGenerator().getCmd( cmdgen.CommunityData('xxx', 'yyy', 1), cmdgen.UdpTransportTarget(('192.168.155.164', 161)), (1,3,6,1,4,1,18489,1,2,4,2,8,0))

logging.info("Error on Get")
logging.info(errorIndication)

logging.info("Error Status")

novice20 17 Junior Poster

with filezilla, upload worked. Then it must be a bug in my script?:(

ftplib.error_perm: 552 File not recognized
i: Bad object type: 1

this is what i got...n i learnt that 552 relates to storage allocation exceeded. but my file is only 6,965 KB

novice20 17 Junior Poster

You should first check the server by using a standard ftp client like filezilla.

with filezilla, upload worked. Then it must be a bug in my script?:(

novice20 17 Junior Poster

hi...

I have written a script for FTP upload using python..

It worked fine when i tried on local boards, but is giving me an error when trying with a remote board via VPN.
this is the error i get:
(104, 'Connection reset by peer')

the machine i developed script on had python2.5 and the one which i am currently running(remote conn) has python 2.4.3

novice20 17 Junior Poster

below is how an snmp get is issued using pysnmp

errorIndication,errorStatus,errorIndex,varBinds = cmdgen.CommandGenerator().getCmd( cmdgen.CommunityData('xxxx', 'xxxx', 1), cmdgen.UdpTransportTarget(('192.168.5.157', 161)), (1,3,6,1,4,1,18489,1,2,1,4,5,1,0))

In the OID part, the integer in bold keeps changing from 1 to 38.
I need to put the above in a loop, instead of issuing 38 seperate gets.

how can this single integer within OID can be looped using a for loop in python?

novice20 17 Junior Poster

thanx for the reply...but the value is an octet string, n when i tried startswith, it said octetstring has no attribute startswith

yes...i got a simple solution..

here s it, hoping it might help some newbie like me:)

if value[:4]== '4501':
print "xxx..whatever..."

novice20 17 Junior Poster

Don't need to .split('-') but you can check directly begining by startswith.

thanx for the reply...but the value is an octet string, n when i tried startswith, it said octetstring has no attribute startswith

novice20 17 Junior Poster

hi...

I have a value, value=4501-E001

I am concerned about only the value before hyphen i.e., 4501

I need to check whether various values begin with 4501, followed by something, n am not concerned about "something" that follows.

How can this splitting be done in python?

novice20 17 Junior Poster

To help you get started,

filelocation = raw_input("Please enter file location:")

thank u..it worked:)

novice20 17 Junior Poster

hi...


how can this be done using python

1.prompting user for a file location from within a script
2.reading the file location entered by the user
3.storing it in a file like object

novice20 17 Junior Poster

If there is only 1 pair, you should get the value with

value = varBinds[0][1]

This value's type is probably this Integer class http://twistedsnmp.sourceforge.net/pydoc/pysnmp.asn1.univ.html#Integer or a similar class. Since the class has an __int__ method, you should be able to convert it directly to a python int:

n = int(value)

thanks a lot...:) it helped

novice20 17 Junior Poster

hi...

am using pysnmp module to do an snmp get on a USB key status

from pysnmp.entity.rfc3413.oneliner import cmdgen

#--query on ccmSDIDUKeyStatus
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd( cmdgen.CommunityData('xxx', 'xxx', 1), cmdgen.UdpTransportTarget(('192.168.5.157', 161)), (1,3,6,1,4,1,18489,1,2,4,2,8,0))

varBinds gives the following:

[(ObjectName('1.3.6.1.4.1.18489.1.2.4.2.8.0'), Integer('2'))]

I need to print the key status, based on varBinds, it is connected if Integer('1'), disconnected if Integer('2')

I have read that, varBinds is a 'tuple of managed objects' and 'each managed object is a pair of Object Name and Object Value'.

By this, I understand that, my varBinds gives me 1 managed object(name,value pair)


I need to access this 'value' from varBinds

how can I do it??

any help is welcome

novice20 17 Junior Poster

Is there any method or library to translate pysnmp OIDs to human readable strings??

novice20 17 Junior Poster

Thanx a lot:) it worked..any better approaches pls....

now that i have installed python-2.6, I want to install yapsnmp

when i try to download n configure yapsnmp-0.7.8, it gives

configure: error: Couldn't find libsnmp


n when i try running the netsnmp.py present under Python-2.6.2\yapsnmp-0.7.8\src, it gives:

ImportError: No module named netsnmpc

can anybody pls help me out??

novice20 17 Junior Poster

Reproduced from www.serverfault.com:

Python 2.6 isn't available in lenny, you need to add either the testing (haven't tried this) or unstable (which is currently sid).

$ sudo apt-get install python2.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Couldn't find package python2.6
Edit the /etc/apt/sources.list so that it looks similar to this:

deb http://ftp.uk.debian.org/debian lenny main
deb http://security.debian.org/ lenny/updates main

# so we can get latest packages
deb http://ftp.uk.debian.org/debian unstable main
Next, run apt-get update then run apt-get install python2.6. To run it, the command is python2.6 (or you can obviously create a symlink if you want it to be default).

I'm not sure if this is the best way, but it works well. I welcome others to suggest a better approach

Thanx a lot:) it worked..any better approaches pls....

novice20 17 Junior Poster

hi...i am trying to install python 2.6 on my debian system..

I followed the following instructions http://www.fps-gamer.net/installing-python-2-6-on-debian-lenny/

on doing aptitude install -t testing python-central

i get

E: Invalid record in the preferences file, no Package header


can any body pls reason out:(

novice20 17 Junior Poster

I want some insight into /etc/apt/preferences and /etc/apt/sources.list file on debian

novice20 17 Junior Poster

I have python 2.5.2 on my Debian system n want to upgrade it to python 2.6.


Got to know that apt-get install package searches for package in /etc/apt/sources.list

I have downloaded python 2.6.2. How to add an entry to the file /etc/apt/sources.list ? :(

novice20 17 Junior Poster

On most linux distributions, you get the file Python.h by installing a package named python-devel.

python 2.5.2 has cum with my debian distribution. How to install python-devel u talked of? is it to be installed above python 2.5.2?

novice20 17 Junior Poster

while trying to install net-snmp-5.6, i get following error

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c netsnmp/client_intf.c -o build/temp.linux-i686-2.5/netsnmp/client_intf.o
netsnmp/client_intf.c:1:20: error: Python.h: No such file or directory
In file included from /usr/local/include/net-snmp/net-snmp-includes.h:69,
from netsnmp/client_intf.c:4:

my debian system has python2.5.2

where can I find Python.h header file??

novice20 17 Junior Poster

i have a problem...

within my python script which does an snmpwalk, there should be an intelligence to create a static table which maps OIDs to corresponding text strings, query the table and in the output of snmpwalk, i need to replace the numeric string with its textual string..

for example

I want

:enterprises.18489.1.2.1.5.1.10.0 = INTEGER: 1
to be replaced with ...........XXXXX=INTEGER:1

any suggestions?

am not at all finding any way of creating tables in python...:( anyone out there pls throw some light on it

novice20 17 Junior Poster

i have a problem...

within my python script which does an snmpwalk, there should be an intelligence to create a static table which maps OIDs to corresponding text strings, query the table and in the output of snmpwalk, i need to replace the numeric string with its textual string..

for example

I want

:enterprises.18489.1.2.1.5.1.10.0 = INTEGER: 1
to be replaced with ...........XXXXX=INTEGER:1

any suggestions?

novice20 17 Junior Poster

I can't tell you where yapsnmp looks for libsnmp. On my mandriva system I have

[~] sudo updatedb
[~] locate libsnmp
/usr/lib64/libsnmp.so.15
/usr/lib64/libsnmp.so.15.1.2
/usr/lib64/libsnmp.so.20
/usr/lib64/libsnmp.so.20.0.0

You probably shouldn't have downloaded libsnmp from softpedia.com. Most libraries are available in packages specific to your linux distribution (ubuntu perhaps ?). So you should first learn about your software manager and find which package contains libsnmp and install that package correctly. Only programs which don't exist in packages should be installed 'by hand' (this is probably the case of yapsnmp).

I am using a Debian system and could locate this

Debian:/usr/lib/python2.5# locate libsnmp.so
/usr/lib/libsnmp.so.15
/usr/lib/libsnmp.so.15.1.0


yet i have the above error

novice20 17 Junior Poster

You probably did not install a package containing libsnmp on your machine (I assume you're running linux). Try to list the available packages which name contains 'snmp'. Also use google with the name of your OS and the word libsnmp.

i downloaded the libsnmp package from the following site

http://linux.softpedia.com/get/Programming/Libraries/libsnmp-19579.shtml

the installation was successful. still i get the above mentioned message. what is the path that yapsnmp searches to find libsnmp?

novice20 17 Junior Poster

while trying to configure yapsnmp-0.7.8, i get the following..


checking for patch... patch
checking for kstat_open in -lkstat... no
checking for socket in -lsocket... no
checking for HMAC in -lcrypto... no
checking for init_snmp in -lsnmp... no
configure: error: Couldn't find libsnmp


what might be the reason?

novice20 17 Junior Poster

How about attaching a sample file and telling us what part of the data you want to extract? That way those of us who are not network engineers might understand what you want to do. For example, does your file contain data like the following?

.1.3.6.1.2.1.25.3.7.1.1.1537.1 = INTEGER: 1
.1.3.6.1.2.1.25.3.7.1.1.1537.2 = INTEGER: 2
.1.3.6.1.2.1.25.3.7.1.1.1537.3 = INTEGER: 3
.1.3.6.1.2.1.25.3.7.1.2.1537.1 = STRING: "/dev/hdb1"
.1.3.6.1.2.1.25.3.7.1.2.1537.2 = STRING: "/dev/hdb2"
.1.3.6.1.2.1.25.3.7.1.2.1537.3 = STRING: "/dev/hdb3"
.1.3.6.1.2.1.25.3.7.1.3.1537.1 = STRING: "0x341"
.1.3.6.1.2.1.25.3.7.1.3.1537.2 = STRING: "0x342"
.1.3.6.1.2.1.25.3.7.1.3.1537.3 = STRING: "0x343"
.1.3.6.1.2.1.25.3.7.1.4.1537.1 = INTEGER: 14877060 KBytes
.1.3.6.1.2.1.25.3.7.1.4.1537.2 = INTEGER: 9920624 KBytes
.1.3.6.1.2.1.25.3.7.1.4.1537.3 = INTEGER: 0 KBytes
.1.3.6.1.2.1.25.3.7.1.5.1537.1 = INTEGER: 1
.1.3.6.1.2.1.25.3.7.1.5.1537.2 = INTEGER: 3
.1.3.6.1.2.1.25.3.7.1.5.1537.3 = INTEGER: 0

I copied that from http://www.unleashnetworks.com/resources/articles/95-work-with-output-from-snmpwalk.html but I don't know what portion of the file you want to extract.

Exactly!!
my file contains similar data
for example, say from the above file, i need to extract only

.1.3.6.1.2.1.25.3.7.1.2.1537.1 = STRING: "/dev/hdb1"
.1.3.6.1.2.1.25.3.7.1.2.1537.2 = STRING: "/dev/hdb2"
.1.3.6.1.2.1.25.3.7.1.2.1537.3 = STRING: "/dev/hdb3"
.1.3.6.1.2.1.25.3.7.1.3.1537.1 = STRING: "0x341"
.1.3.6.1.2.1.25.3.7.1.3.1537.2 = STRING: "0x342"
.1.3.6.1.2.1.25.3.7.1.3.1537.3 = STRING: "0x343"

and

.1.3.6.1.2.1.25.3.7.1.5.1537.2 = INTEGER: 3
.1.3.6.1.2.1.25.3.7.1.5.1537.3 = INTEGER: 0

how can this be done??

novice20 17 Junior Poster

I am also new to Python so I can't tell you too much about it. But open() should be what you're looking if you want to read and write files.

rf = open( 'FILE PATH', 'r' ) 
Input=rf.readlines() # Reads the lines
rf.close()

open('file path','w') is for writing
Here is a reference. http://docs.python.org/tutorial/inputoutput.html

thanks for the reply:) but this is not what I am looking for. readlines() just reads all the lines in the file. I need to read only a selected part of it

novice20 17 Junior Poster

hi...

is there any MIB parsing tool which generates an excel file or like that can be queried?

novice20 17 Junior Poster

hi....


I am doing an snmpwalk on MIB variables and dumping the output to a text file.
I dont need all the info and need to read only a part of it.

How can this be done efficiently in python?

novice20 17 Junior Poster

hi all...


whats the difference between os.popen and subprocess.popen??

what does shell=True in subprocess.call really mean?

if os.popen is used for snmpwalk, will there be any problem such as exceeding pipe capacity? what is the capacity of the file objcet connected to pipe using os.popen?/ how much data can it hold?

novice20 17 Junior Poster

Did you try

for n in range(1,16):
    subprocess.call(
        'snmpset -v2c -c arct1c 192.168.5.157 .1.3.6.1.4.1.18489.1.2.1.5.1.2.0 i %d' % n,
        shell = True)

?

3 cheers:) thnx a lot Gribouillis..it's working:)

novice20 17 Junior Poster

Do you actually mean n (wihtout '') or str(n) in your code?

thanks for the replies...the n in my code shoul be substituted with 1,2 3,.......upto 15

novice20 17 Junior Poster

hi all


can u pls help me regarding iterating through an integer variable within a subprocess call


here is what i exactly want to do
for n in range(1,16):
subprocess.call()
i.e.,
i want to iterate through snmpwalk..but its not working:(


it shows 'bad value name n'

pls help me out
thanks in advance

novice20 17 Junior Poster

can anyone help me regarding how multiple snmp sets can be invoked in python within a for loop?

novice20 17 Junior Poster

Why am I not able to edit my unix file though i have the permissions -rwxrwxrwx? :(