how to save all the received message to a file

1. create a list, data []

2. define a function, to send commands, and receive the response, then append the response to the list

def srp (s, send, recv=”recv”, wait = 2):
send = s.send(“{}\n”.format (send))
recv = s.recv(5000000)
return recv

3. you can execute some commands and put all in the list

srp (s, “conf t”)
srp (s, “interface loop 111”)
srp (s, “ip address x.x.x.x/32”)
srp (s, “no shut”)

4. write the list to a file

f = open (“SWAN_install_uninstall_logs.txt”, “w”)
for line in data:
f.write (“{}\n”.format(line))

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: