为什么我的标准输出会干扰我在 python 中的网页? [英] Why is my stdout interfering with my webpage in python?

查看:44
本文介绍了为什么我的标准输出会干扰我在 python 中的网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常简单的代码,只需使用 scapy 触发一个 pcap(数据包),

Really simple code that just fires one pcap (packet) using scapy,

如果我只想对自己执行简单的 cgi-bin POSTS 以运行一组 10 个简单的测试,为什么这只是作为文本(而不是网站)返回.如果我注释掉该行

If I just want to do simple cgi-bin POSTS to myself to run a set of 10 easy tests why is this just kicking back as text (rather than a website). If I comment out the line

sendp(a, iface="em1")

然后下面的代码实际上可以很好地生成网站......但它实际上不会发送数据包,我想这是带有标准输出的东西......欢迎提出建议!

Then the below code actually generates the website fine... but it won't actually send the packet, I imagine this is something with stdout.... suggestions are welcome!

#!/usr/local/bin/python

from scapy.all import *
#import v6tester_main

print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>NPD Automation Tool - GCT-USG</title>'
print '</head>'
print '<body>'
print '<font> NPD Automation Tool </font>'

a = Ether() / IP() / IPv6() / ICMPv6EchoRequest()
sendp(a, iface="em1")

print '<br>'
print '<font>End of Test</font>'
print '</body>'
print '</html>'

如果我查看源代码,我会看到这个->

If I view source I see this->

<html>
<head>
<title>NPD Automation Tool - GCT-USG</title>
</head>
<body>
<font> NPD Automation Tool </font>

Sent 1 packets.
<br>
<font>End of Test</font>
</body>
</html>

推荐答案

很可能 sendp 的输出使 HTML 变得如此糟糕,以至于它显示为文本,您可以做的是尝试将 verbose=0 传递给 sendp(如果输出不重要),或尝试其他详细级别.如果 sendp 的输出对您很重要,您可以在单独的脚本中运行它使用 subprocess.Popen 并尝试格式化输出以使其适合 HTML 页面.

Most probably the output of sendp brakes the HTML so bad it shows as text, what you can do is try pass verbose=0 to sendp (if the output is not important), or try other verbose level. if the output of sendp is important to you, you can run it in a separate script with subprocess.Popen and try to format the output so it fit in the HTML page.

操作,有人已经回答了几乎相同

edit: ops, someone already answered with almost the same

这篇关于为什么我的标准输出会干扰我在 python 中的网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆