我正在设置一个bash脚本来自动构建LAMP环境.
我debconf-set-selections在安装mysql,phpmyadmin等之前用来设置选项...
它的工作原理很棒.但问题是我必须为mysql设置一个空密码,并且在安装过程中它仍然要求输入密码,即使在之前键入的行:
echo "mysql-server-5.5 mysql-server/root_password password" | debconf-set-selections
echo "mysql-server-5.5 mysql-server/root_password_again password" | debconf-set-selections
Run Code Online (Sandbox Code Playgroud) 我需要检查一个给定的浮点数是否在给定的容差范围内接近浮点数组中的任何浮点数.
import numpy as np
# My float
a = 0.27
# The tolerance
t = 0.01
# Array of floats
arr_f = np.arange(0.05, 0.75, 0.008)
Run Code Online (Sandbox Code Playgroud)
有一个简单的方法吗?有什么比这样if a in arr_f:但是允许区别的容忍度?
加
"允许容忍"我的意思是以下意义:
for i in arr_f:
if abs(a - i) <= t:
print 'float a is in arr_f within tolerance t'
break
Run Code Online (Sandbox Code Playgroud) 我们可以将srp()函数用于第3层ICMP数据包吗?我看到当我们制作ICMP echo-request数据包并使用sr()发送/接收时,我们看不到它被发送出接口,因此没有来自目的地的响应.但是如果我们使用srp()函数,我们会看到相同的数据包响应.什么时候应该使用sr()和srp()?在文档中,它声明sr()将用于L3数据包,而srp()将用于L2?但在我的情况下,我不确定为什么sr()不适用于ICMP数据包?有些专家可以帮我理解吗?
如果总是需要"iface"论证,也有人可以告诉我.没有它,scapy将如何知道它应该发送数据包的接口?
情况1:使用iface作为参数的sr()函数:
sr(icmp,iface="eth0")
Run Code Online (Sandbox Code Playgroud)
开始排放:
WARNING: Mac address to reach destination not found. Using broadcast.
Finished to send 1 packets.
^C
Received 0 packets, got 0 answers, remaining 1 packets
(<Results: TCP:0 UDP:0 ICMP:0 Other:0>, <Unanswered: TCP:0 UDP:0 ICMP:1 Other:0>)
Run Code Online (Sandbox Code Playgroud)
上面我没有看到来自IP 192.168.25.1的任何ICMP响应
案例2:没有iface的sr()函数:
sr(icmp)
.Begin emission:
......WARNING: Mac address to reach destination not found. Using broadcast.
.Finished to send 1 packets.
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................^C
Received 887 packets, got 0 answers, remaining 1 packets
(<Results: TCP:0 UDP:0 ICMP:0 Other:0>, <Unanswered: TCP:0 UDP:0 …Run Code Online (Sandbox Code Playgroud) concurrent.futures.ProcessPoolExecutor如果父进程因任何原因终止,是否有办法使进程终止?
一些细节:我正在ProcessPoolExecutor处理大量数据的工作中使用。有时我需要使用kill命令终止父进程,但是当我这样做时,进程会ProcessPoolExecutor继续运行,我也必须手动终止它们。我的主要工作循环如下所示:
with concurrent.futures.ProcessPoolExecutor(n_workers) as executor:
result_list = [executor.submit(_do_work, data) for data in data_list]
for id, future in enumerate(
concurrent.futures.as_completed(result_list)):
print(f'{id}: {future.result()}')
Run Code Online (Sandbox Code Playgroud)
executor如果父进程死亡,我可以在此处添加什么或做不同的事情来使子进程终止吗?
我是scapy的新手,我正在尝试使用sr和sr1函数来理解他们的工作.
我试图制作以下数据包,我发现它已经发送了1个数据包,但它说它收到了581个数据包.有人可以帮助我理解为什么它显示了这么多收到的数据包.
收到1373个数据包,得到0个答案,剩下1个数据包
>>> p=sr(IP(dst="192.168.25.1")/TCP(dport=23))
.Begin emission:
.....Finished to send 1 packets.
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................^C
Received 581 packets, got 0 answers, remaining 1 packets
>>> p
(<Results: TCP:0 UDP:0 ICMP:0 Other:0>, <Unanswered: TCP:1 UDP:0 ICMP:0 Other:0>)
Run Code Online (Sandbox Code Playgroud)
我的TCPDump输出没有显示它收到这么多数据包.
我在 CentOS6 上安装了 ProFTPD 服务器。如果我使 ftp 本地主机,我可以正确连接,但如果我从外部尝试,我会收到消息“没有到主机的路由”。但有一条到主机的路由,因为我是通过 SSH 连接的。
我尝试添加以下 iptable 规则:
iptables -A INPUT -p tcp -m tcp --dport 21 -m conntrack --ctstate ESTABLISHED -j ACCEPT -m comment --comment "Allow ftp connections on port 21"
iptables -A OUTPUT -p tcp -m tcp --dport 21 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT -m comment --comment "Allow ftp connections on port 21"
iptables -A INPUT -p tcp -m tcp --dport 20 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT -m comment --comment "Allow ftp …Run Code Online (Sandbox Code Playgroud) 我有两个向量,v1和v2。我想v2从的每个值中减去的每个值v1并将结果存储在另一个向量中。我也想使用非常大的向量(例如1e6大小),因此我认为我应该使用numpy来提高性能。
到目前为止,我有:
import numpy
v1 = numpy.array(numpy.random.uniform(-1, 1, size=1e2))
v2 = numpy.array(numpy.random.uniform(-1, 1, size=1e2))
vdiff = []
for value in v1:
vdiff.extend([value - v2])
Run Code Online (Sandbox Code Playgroud)
这将创建一个包含100个条目的列表,每个条目都是大小为100的数组。尽管如此,我不知道这是否是最有效的方法。我想以尽可能小的对象大小(内存方式)非常快速地计算1e4期望值。
今天我一直在学习Python中的"for循环".我在Python Shell中键入代码,并SyntaxError: invalid syntax在函数后面显示红色print("I finished")单词print.
words = ["cat", "125", "dog", "pig"]
for word in words:
if word == "125":
print("No spam please!")
break
print("Nice " + word)
else:
print("I am lucky: No spam.")
print("I finished")
Run Code Online (Sandbox Code Playgroud)
但是当我在记事本中编写代码并保存为*.py和使用命令提示符运行时,它可以正常工作并且来:
Nice cat
No spam please!
I finished
Run Code Online (Sandbox Code Playgroud)
第三个"打印"功能错误是什么?
我正在尝试iptables用于负载平衡.我正在和我一起工作virtualbox.所有VM(debian)都在内部网络中,IP是静态的.我想将来自我的Web服务器(apache2)的请求与IP地址路由10.0.0.2:80到服务器的IP地址10.0.0.3:80和192.168.0.2:80另一个网络.网络构造如下:
网关进行IP转发,它有两个接口:eth0用于网络10.0.0.0和eth1网络192.168.0.0.然后有一个带IP地址的负载均衡器10.0.0.2.我试图设置这些规则,但它们不起作用:
iptables -t nat -A PREROUTING -p tcp --dport 80 -m state --state NEW -m statistic --mode nth --every 3 --packet 0 -j DNAT --to-destination 10.0.0.3:80
iptables -t nat -A PREROUTING -p tcp --dport 80 -m state --state NEW -m statistic --mode nth --every 3 --packet 1 -j DNAT --to-destination 192.168.0.2:80
Run Code Online (Sandbox Code Playgroud) 我修改了此处给出的示例代码: getopt 的示例代码
如下,但它不起作用。我不确定我错过了什么。我在现有代码中添加了“-j”选项。最终,我想添加尽可能多的命令选项以满足我的需求。
当我提供如下输入时,它不会打印任何内容。
./pyopts.py -i dfdf -j qwqwqw -o ddfdf
Input file is "
J file is "
Output file is "
Run Code Online (Sandbox Code Playgroud)
你能告诉我这里有什么问题吗?
#!/usr/bin/python
import sys, getopt
def usage():
print 'test.py -i <inputfile> -j <jfile> -o <outputfile>'
def main(argv):
inputfile = ''
jfile = ''
outputfile = ''
try:
opts, args = getopt.getopt(argv,"hij:o:",["ifile=","jfile=","ofile="])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
usage()
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt …Run Code Online (Sandbox Code Playgroud)