我想要得到这个命令的pid.
sudo -b tcpdump -i eth0 port 80 -w eth0.pcap
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 python paramiko 模块连接到 ssh 服务器,但在连接时遇到 BadHostKeyException 异常。任何人都可以重定向我,如何解决这个异常。
import paramiko
def checkSSH(host,user,password,command):
ssh=paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, username=user, password=password)
print ssh.exec_command(command)
ssh.close()
return ssh
username='fakeuser'
password='fakepasswd'
ips = ['2.2.2.2']
response={}
ssh_issue=0
for ip in ips:
try:
print ip
checkSSH(ip,username,password,'date')
except paramiko.BadHostKeyException as e:
print str(e)
#I Need to do something here to get rid of this execption and retry
except:
import traceback
print traceback.format_exc()
response[ip]='SSH_Needs_Reloading'
ssh_issue=1
Run Code Online (Sandbox Code Playgroud) 用例:我想通过 python 请求模块找出主机名支持多少密码。
我找不到提供密码名称来请求模块挂钩的方法。任何人都可以建议提供指定密码的方法。
import ssl
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
class Ssl3HttpAdapter(HTTPAdapter):
""""Transport adapter" that allows us to use SSLv3."""
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(
num_pools=connections, maxsize=maxsize,
block=block, ssl_version=ssl.PROTOCOL_SSLv3)
Run Code Online (Sandbox Code Playgroud) 我想动态创建一个%detail哈希,而不使用eval语句.这段代码可以正常使用eval语句,但有没有更好的方法来执行此操作而不使用eval?
my @input=('INFO: Vikram 32 2012','SAL: 12000$','ADDRESS: 54, junk, JUNK');
my %matching_hash= (
qr/^INFO:\s*(\S+)\s+(\S+)\s+(\S+)/ =>['name','age','joining'],
qr/^SAL:\s*(\S+)/ => ['salary'],
qr/ADDRESS:\s*(.*)/ =>['address']
);
my %detail;
while(my ($regex, $array) = each(%matching_hash)) {
foreach (@input){
if(/$regex/) {
for(my $i=0;$i<=$#$array; $i++) {
$j=$i+1;
eval '$detail{$array->[$i]} = $$j';
}
}
}
}
use Data::Dumper;
print Dumper(\%detail);
++++++++++++++
$VAR1 = {
'name' => 'Vikram',
'address' => '54, junk, JUNK',
'age' => '32',
'joining' => '2012',
'salary' => '12000$'
};
Run Code Online (Sandbox Code Playgroud) 我想从某个文件中删除非ascii字符.我已经尝试了这么多正则表达式.
sed -e 's/[\d00-\d128]//g' # not working
cat /bin/mkdir | sed -e 's/[\x00-\x7F]//g' >/tmp/aa
Run Code Online (Sandbox Code Playgroud)
但是这个文件包含一些非ascii字符.
[root@asssdsada ~]$ hexdump /tmp/aa |more
00 01 02 03 04 05 06 07 - 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF
00000000 45 4C 46 B0 F0 73 38 C0 - C0 BC BC FF FF 61 61 61 ELF..s8......aaa
00000010 A0 A0 50 E5 74 64 50 57 - 50 57 50 57 D4 D4 51 E5 ..P.tdPWPWPW..Q.
00000020 74 64 6C …Run Code Online (Sandbox Code Playgroud) 我想要在Windows中grep上次运行进程的PID.我在后台运行命令.
如何获取这些命令的PID?
我想匹配两个不同的字符串,输出应该是1美元和2美元.根据我在这个例子中,如果$ a是'xy abc',那么$ 1应该是'xy abc'而$ 2应该是'abc',但是'abc' '部分是3美元.你能帮我写一个正则表达式,因为1美元应该有整个字符串而2美元应该有第二部分.我使用的是perl 5.8.5.
my @data=('abc xy','xy abc');
foreach my $a ( @data) {
print "\nPattern= $a\n";
if($a=~/(abc (xy)|xy (abc))/) {
print "\nMatch: \$1>$1< \$2>$2< \$3>$3<\n";
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
perl test_reg.pl
Pattern= abc xy
Match: $1>abc xy< $2>xy< $3><
Pattern= xy abc
Match: $1>xy abc< $2>< $3>abc<
Run Code Online (Sandbox Code Playgroud) 我有两个复杂的数据结构(即_to和_from),我想用_from的相同实体覆盖_to的实体.我举了这个例子.
# I am having two data structure _to and _from
# I want to override _to from _from
_to = {'host': 'test',
'domain': [
{
'ssl': 0,
'ssl_key': '',
}
],
'x': {}
}
_from = {'status': 'on',
'domain': [
{
'ssl': 1,
'ssl_key': 'Xpyn4zqJEj61ChxOlz4PehMOuPMaxNnH5WUY',
'ssl_cert': 'nuyickK8uk4VxHissViL3O9dV7uGSLF62z52L4dAm78LeVdq'
}
]
}
### I want this output
_result = {'host': 'test',
'status': 'on',
'domain': [
{
'ssl': 1,
'ssl_key': 'Xpyn4zqJEj61ChxOlz4PehMOuPMaxNnH5WUY',
'ssl_cert': 'nuyickK8uk4VxHissViL3O9dV7uGSLF62z52L4dAm78LeVdq'
}
],
'x': {}
}
Run Code Online (Sandbox Code Playgroud)
用例2:
_to = {'host': …Run Code Online (Sandbox Code Playgroud)