-1

I'm trying to communicate with a http server which is running on debian strech from a brand new out of the box cisco device. Now, the so called zero touch configuration is no problem:

  • The Switch gets an IP address and such via DHCP and a link to where to fetch it's initial configuration.
  • The switch gets its basic configuration such as user credentials etc.
    The problem rises when I try to search through a database on the server from the switch. In this database some variables are stored. Depending the serialnumber of the switch, it should receive a specific hostname, Mgmt address etc.

On those new switches there is a python module integrated so I ran some tests. I tried to fetch the serial number and got them whithout any problems. The moment I tried to write the serial number on a txt file on the server I got this error

Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: 'http://10.232.152.19:80/temp.txt'

Code so far:

from cli import cli
def get_serial():
    serial = cli("show version | include System Serial\n")
    serial = (serial.split()[-1])
    f = open ("http://10.232.152.19:80/temp.txt", "a")
    f.write(serial)
    f.close
    get_serial()
Heikki
  • 2,214
  • 19
  • 34
Michael
  • 57
  • 9

1 Answers1

1

The problem you are facing is because you are trying to open a file from the network. You need to download the file first in you system and then open it. You should use urllib to fetch the file and then open it. then save it and again push it back.

import urllib
txt = urllib.urlopen(target_url).read()
Arghya Saha
  • 5,599
  • 4
  • 26
  • 48
  • with the target url "http://10.232.152.19/var/www/html/temp.txt" I get a "network unreachable" and with target url ""http:\\10.232.152.19:80\temp.txt"" I get a "no host given", same result with the complete path or abbreviated path. (sidenote: it is reachable via a webbrowser on my local machine) – Michael Apr 02 '19 at 07:32