我想运行tcpdump一些参数(仍然不知道要使用什么),然后加载stackoverflow.com页面.
输出应该是HTTP通信.后来,我想将它用作shell脚本,所以每当我想检查站点site.com的HTTP通信时,我就可以运行了script.sh site.com.
HTTP通信应该足够简单.像这样:
GET /questions/9241391/how-to-capture-all-the-http-communication-data-using-tcp-dump
Host: stackoverflow.com
...
...
HTTP/1.1 200 OK
Cache-Control: public, max-age=60
Content-Length: 35061
Content-Type: text/html; charset=utf-8
Expires: Sat, 11 Feb 2012 15:36:46 GMT
Last-Modified: Sat, 11 Feb 2012 15:35:46 GMT
Vary: *
Date: Sat, 11 Feb 2012 15:35:45 GMT
....
decoded deflated data
....
Run Code Online (Sandbox Code Playgroud)
现在,我应该使用哪些选项tcpdump来捕获它?
我抓住这样的例外,
def get_url_fp(image_url, request_kwargs=None):
response = requests.get(some_url, **request_kwargs)
response.raise_for_status()
return response.raw
try:
a = "http://example.com"
fp = get_url_fp(a)
except HTTPError as e:
# Need to check its an 404, 503, 500, 403 etc.
Run Code Online (Sandbox Code Playgroud) 我正在试图找出要做文件操作的通配符.
我将这些文件放在目录中以进行测试:
file_BSD.GIF file_linux.gif file_unix
Run Code Online (Sandbox Code Playgroud)
看我的ls命令,
$ ls *{.GIF,.gif}
file_BSD.GIF file_linux.gif
Run Code Online (Sandbox Code Playgroud)
哪个可以.
但"查找"似乎没有同样的方式:
$ find -name *{.GIF,.gif}
find: paths must precede expression: file_linux.gif
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我已经读过"-iname"应该找到大写和小写文件,但这似乎也不起作用:
$find -iname *.gif
./file_linux.gif
Run Code Online (Sandbox Code Playgroud)
(这也应该找到.GIF文件,对吧?).
以下是我的脚本:
<?php
$connection = ssh2_connect('XX.XX.XX.XX', 22);
ssh2_auth_password($connection, 'root', '******');
$stream = ssh2_exec($connection, 'useradd -d /home/users/test -m testftp');
$stream = ssh2_exec($connection, 'passwd testftp');
$stream = ssh2_exec($connection, 'password');
$stream = ssh2_exec($connection, 'password');
?>
Run Code Online (Sandbox Code Playgroud)
它显示以下错误:
Fatal error: Call to undefined function ssh2_connect() in /home/chaosnz/public_html/fotosnap.net/test.php on line 2
Run Code Online (Sandbox Code Playgroud)
我怎么处理这个?
谢谢
我发现有很多页面说明如何解压缩tar.bz2文件,但是如何解压tar.bz文件呢?
很抱歉这个简单的问题,但我正在度假阅读一本关于核心音频的书,并没有我的C或Objective C书籍...
这个变量定义中的花括号是什么?
MyRecorder recorder = {0};
Run Code Online (Sandbox Code Playgroud) 假设我们有这个数据文件.
john 32 maketing executive
jack 41 chief technical officer
jim 27 developer
dela 33 assistant risk management officer
Run Code Online (Sandbox Code Playgroud)
我想打印使用 awk
john maketing executive
jack chief technical officer
jim developer
dela assistant risk management officer
Run Code Online (Sandbox Code Playgroud)
我知道可以用它来完成for.
awk '{printf $1; for(i=3;i<NF;i++){printf " %s", $i} printf "\n"}' < file
Run Code Online (Sandbox Code Playgroud)
问题是它长而且看起来很复杂.
是否有其他简短的方法来打印其余的字段.
这实际上是语言不可知的.但我会在python中给你上下文.
我有这个父类
class Mammal(object):
def __init__(self):
""" do some work """
def eat(self, food):
"""Eat the food"""
way_to_eat = self._eating_method()
self._consume(food)
def _eating_method(self):
"""Template method"""
def _consume(self, food):
"""Template method"""
Run Code Online (Sandbox Code Playgroud)
这eat是唯一的公共方法,而_consume和_eating_method实际保护将由子类来实现的方法.
当你只写了这门Mammal课时,你会测试什么?
显然所有4种方法.
现在让我们介绍一个孩子
class Tiger(Mammal):
def _eating_method(self):
"""Template method"""
def _consume(self, food):
"""Template method"""
Run Code Online (Sandbox Code Playgroud)
看看这堂课.它只有2种受保护的方法.
我应该测试所有4种方法Tiger(包括2种继承)还是只测试引入的变化(仅覆盖2种方法)?
什么是理想的情况?
如何在默认情况下在REPL上启用漂亮打印?
目前我通过使用pprint.pprint()功能来做到这一点.
>>> pprint.pprint(data)
{'SHIP_CATEGORY': '',
'SHIP_QUANTITY': 1,
'SHIP_SEPARATELY': 0,
'SHIP_SUPPLEMENT': 0,
'SHIP_SUPPLEMENT_ONCE': 0,
'THUMBNAIL': ''}
Run Code Online (Sandbox Code Playgroud)
但我希望默认打印漂亮
>>> data
{'SHIP_CATEGORY': '',
'SHIP_QUANTITY': 1,
'SHIP_SEPARATELY': 0,
'SHIP_SUPPLEMENT': 0,
'SHIP_SUPPLEMENT_ONCE': 0,
'THUMBNAIL': ''}
Run Code Online (Sandbox Code Playgroud)
我试过了什么?
我在谷歌搜索.没有找到任何大多数结果指向pprint模块
我创建了这样的requestsPOST请求,其中我指定了超时阈值:
response = requests.post(url, data=post_fields, timeout=timeout)
但是,为了确定"良好"的阈值,我想提前对服务器响应时间进行基准测试.
如何计算服务器的最小和最大响应时间?
python network-programming python-3.x python-requests server