我想知道如何ping IP:PORT并将其发送给负载。我找到了一个使用PythonPing
软件包的教程,但我相信PythonPing
中存在一个错误。
from pythonping import ping
ping('8.8.8.8:80', count=1, payload="Custom Message")
错误:
Traceback (most recent call last):
File "PingClient.py", line 1, in <module>
from pythonping import ping
File "/.local/lib/python2.7/site-packages/pythonping/__init__.py", line 2, in <module>
from . import network, executor, payload_provider
File "/.local/lib/python2.7/site-packages/pythonping/executor.py", line 159
print(value, file=self.output)
^
SyntaxError: invalid syntax
还有其他方法吗?
答案 0 :(得分:-1)
我不确定这是否会有所帮助,我对有效负载不熟悉,但这也许行得通吗?
import socket
ip = "ip"
port = 80 or whatever
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, port))
msg = "hello"
s.send(msg.encode('utf-8'))
或者如果您想使用udp
import socket
ip = "ip"
port = 80 or whatever
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
msg = "hello"
s.sendto(msg, (ip, port))