pls help me with this code

pls help me with this code

Postby chronos » Sat Nov 02, 2013 3:26 pm

Code: Select all
import socket
def retBanner(ip, port):
    try:
        socket.setdefaulttimeout(2)
        s = socket.socket()
        s.connect((ip, port))
        banner = s.recv(1024)
    except:
        return banner
    def main():
        ip1 = '192.168.234.129'
        ip2 = '192.168.234.131'
        port = 22
        banner1 = retBanner(ip1, port)
if banner1:
    print '[+] ' + ip1 + ': ' + banner1
        banner2 = retBanner(ip2, port)
if banner2:
    print '[+] ' + ip2 + ': ' + banner2
if __name__ == '__main__':
    main()



the error code is: ip1 is not defined.
Last edited by Yoriz on Sat Nov 02, 2013 4:02 pm, edited 1 time in total.
Reason: First post lock, Added code tags
chronos
 
Posts: 1
Joined: Sat Nov 02, 2013 3:09 pm

Re: pls help me with this code

Postby Yoriz » Sat Nov 02, 2013 4:05 pm

Hi, welcome to the forum.
Please read the 'new users read this' link in my signature.
I added code tags to your code please use them as stated in the link otherwise the indentation of your code is not shown.

Your if banner1 and if banner2 are not indented to be inside your main function, hence ip1 is local to main function and throws the error, also main def indentation is wrong.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 871
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to Networking

Who is online

Users browsing this forum: No registered users and 1 guest