Dec-19-2018, 09:14 AM
Hi all,
I am trying to code a script to record what return a networked device.
I can connect to that device via RAW PuTTY. The device first return :
The output has the below xml form and each time that device is being solicited, I can directly see on PuTTY what is going on :
I have started the below code, but I struggle to get an ongoing return once the session is open and the first few exchanges for authentification done.
I guess I need to use something else than recv(), like listen() to get this returned value in realtime, but I cannot figure it out. Below if the latest working code. Any help would be really appreciated.
I am trying to code a script to record what return a networked device.
I can connect to that device via RAW PuTTY. The device first return :
Output:Connection Accepted
I have then to use my credential to be authorised on that device and can input the below :Quote:U Userthis provide me with the below confirmation :
P Password
A
Output:<?xml version="1.0"?><Status Command="A"><State>AUTH_SUCCESS</State></Status>
What I am trying to achieve is to use a specific command from the device API providing any change of status in realtime.The output has the below xml form and each time that device is being solicited, I can directly see on PuTTY what is going on :
Output:</Status>
<?xml version="1.0"?><Status Command="J">
<Zone id="11" state="1"/>
<Zone id="12" state="1"/>
<Zone id="13" state="1"/>
<Zone id="14" state="1"/>
</Status>
<?xml version="1.0"?><Status Command="J">
<Zone id="21" state="1"/>
<Zone id="22" state="1"/>
</Status>
<?xml version="1.0"?><Status Command="J">
<Zone id="1" state="1"/>
<Zone id="2" state="1"/>
<Zone id="3" state="1"/>
<Zone id="4" state="1"/>
<Zone id="5" state="1"/>
<Zone id="6" state="1"/>
<Zone id="7" state="1"/>
<Zone id="8" state="1"/>
<Zone id="9" state="1"/>
</Status>
I would like to record this output on real-time and logging it in .csv file using python.I have started the below code, but I struggle to get an ongoing return once the session is open and the first few exchanges for authentification done.
I guess I need to use something else than recv(), like listen() to get this returned value in realtime, but I cannot figure it out. Below if the latest working code. Any help would be really appreciated.
import socket import time import sys s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) HOST='172.18.0.45' PORT='8020' BUFF= 1024 user='KPI' pwd='KPI' PORT=int(PORT) #return connection issue try: s.connect((HOST, PORT)) except: print('Connection error') sys.exit #def(VTP,arg) start an entire formula with whats below user=str.encode('U '+ user +'\n\r') pwd=str.encode('P '+ pwd +'\n\r') ack=str.encode('A\n\r') logVTP=str.encode('J ON\n\r') s.send(user) s.send(pwd) s.send(ack) data = s.recv(1024) print ("received data:", data) s.send(logVTP) data = s.recv(1024) print ("received data:", data) s.close()