Pinging a machine from python
I tried pinging a machine from python using socket programming but could not do it. Is there any module which we can use to ping the machine < like net::ping in perl> or can you give me simple program. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pinging a machine from python
On May 26, 5:21 am, Zerge <[EMAIL PROTECTED]> wrote: > On May 25, 11:13 am, Prasanth <[EMAIL PROTECTED]> wrote: > > > I tried pinging a machine from python using socket programming but > > could not do it. Is there any module which we can use to ping the > > machine < like net::ping in perl> or can you give me simple program. > > Import OS > ip=192.168.1.1 > pingtext="ping "+ip+" -n 1" > pingresult=os.popen(pingtext).readlines() > > "OS" gives you access to the command line of the operating system. Thanks for the solution guys. But the above program is giving the output as : If we print pingresult it is giving the output as : ['\r\n', 'Pinging 0.168.1.1 with 32 bytes of data:\r\n', '\r\n', 'Request timed out.\r\n', '\r\n', 'Ping statistics for 0.168.1.1:\r \n', 'Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),\r\n'] my requirement is IP address and whether the machine is pinging or not. we should not display the above output. However we can do it by using regular expression or there is any other way. Please suggest. Thanks, Prasanth. -- http://mail.python.org/mailman/listinfo/python-list
How to call a method returning a value from a main function
#!/sur/bin/env python
import sys
import jwt
import argparse
from calendar import timegm
from datetime import datetime
import uuid
class TokenGenerator:
def __init__(self, args):
self.macKey = args.authzSystemMacKey
self.authzSystemId = args.authzSystemId
self.permissions = args.permissions
self.configurationId = args.configurationId
self.tokenExpiry = args.tokenExpiryInSeconds
def generate(self):
payload = {
'iss': self.authzSystemId,
'aud': 'qed:' + self.configurationId,
'sub': 'admin:tokengen.py',
'qedp': self.permissions,
'exp': timegm(datetime.utcnow().utctimetuple()) + self.tokenExpiry
}
if self.tokenExpiry <= 300: # less than 5minutes
payload['jti'] = str(uuid.uuid1())
return jwt.encode(payload, self.macKey, algorithm='HS256')
class JWTParms:
pass
def GenAccessToken(mackey,authid,configid,tokenexp,*perm):
args=JWTParms()
args.configurationId=configid
args.authzSystemMacKey=mackey
args.authzSystemId=authid
args.tokenExpiryInSeconds=tokenexp
args.permissions=perm
tokenGen=TokenGenerator(args)
tok=tokenGen.generate()
return tok
if __name__ == '__main__':
GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long",
"default", "default", 6,
"g,m,a,s,c,p,d")
when i am calling the above method it is not returning any value but when i use
print it is printing the value. Is there any wrong in returning the value from
above method. Please help me ASAP
--
https://mail.python.org/mailman/listinfo/python-list
