mirror of
https://github.com/aaPanel/aaPanel.git
synced 2026-08-17 21:25:47 +02:00
Since version 7.7.0, we recommend yours update python to 3.12. [+] Using nginx technology to load static files improves access speed [+] Refactor homepage, website, FTP, and database using vue3 [+] Table loading changed to skeleton screen [+] Add Website statistics-v2 professional plug-in [+] Add Home page - top 5 resource occupancy [+] Add protection for Files management (requires Tamper-proof for Enterprise 3.7) [+] Website, FTP, Databases page add program status [+] Add FTP log analysis (only supports Centos) [+] Add password-free login to phpMyAdmin [+] Add Proxy Project in Website (Supported when web service uses Nginx) [+] Add WP Toolkit (Pro version only) [+] Redesigned Docker module [+] Add WP Toolkit Protection [+] Add WP Toolkit Backup and Restore [+] Add WP Toolkit Migrated [+] Add WP Toolkit Clone site (supports new domain and subdomain) [+] Add WP Toolkit Create site from backup of other panel [+] Add WP Toolkit support for Cron automatic backup (only save Local disk) [+] Add WP Toolkit operation log [+] Add Integrity check for WP Toolkit [+] Add WP Toolkit plug-in management and themes management [*] Optimize phpMyAdmin formula access method [*] Optimize Home page PHP display problem [*] Optimize jump to the login interface after the login expires [*] Optimize automatic renewal of SSL at some times [*] Optimize Let's Encrypt to increase application success rate [-] Fix Logs Audit cannot be opened [-] Fix apache URL rewrite issue [-] Fix phpmyadmin installation problem [-] Fix the problem that some servers cannot install software [-] Fix upload file error [-] Fix left menu hiding problem [-] Fix aaPanel Mobile QR code display problem [-] Fix problem that third-party plug-ins are not displayed in the App Store [-] Fix issue where the menu bar is blank when opening new tabs [-] Fixed panel not being accessible in some cases [-] Fix the issue where Curl warning caused the inability to apply for SSL [-] Fix Quota issues for Website, FTP, Databases [-] Fix file interface display problem on mobile terminal
88 lines
2.9 KiB
Python
88 lines
2.9 KiB
Python
#!/usr/bin/env python
|
|
#coding:utf-8
|
|
import os, sys, socket, struct, select, time
|
|
|
|
def checksum(source_string):
|
|
sum = 0
|
|
countTo = (len(source_string)/2)*2
|
|
count = 0
|
|
while count<countTo:
|
|
thisVal = ord(source_string[count + 1])*256 + ord(source_string[count])
|
|
sum = sum + thisVal
|
|
sum = sum & 0xffffffff
|
|
count = count + 2
|
|
if countTo<len(source_string):
|
|
sum = sum + ord(source_string[len(source_string) - 1])
|
|
sum = sum & 0xffffffff
|
|
sum = (sum >> 16) + (sum & 0xffff)
|
|
sum = sum + (sum >> 16)
|
|
answer = ~sum
|
|
answer = answer & 0xffff
|
|
answer = answer >> 8 | (answer << 8 & 0xff00)
|
|
return answer
|
|
|
|
def receive_one_ping(my_socket, ID, timeout):
|
|
timeLeft = timeout
|
|
while True:
|
|
startedSelect = time.time()
|
|
whatReady = select.select([my_socket], [], [], timeLeft)
|
|
howLongInSelect = (time.time() - startedSelect)
|
|
if whatReady[0] == []: return
|
|
timeReceived = time.time()
|
|
recPacket, addr = my_socket.recvfrom(1024)
|
|
icmpHeader = recPacket[20:28]
|
|
type, code, checksum, packetID, sequence = struct.unpack("bbHHh", icmpHeader)
|
|
if packetID == ID:
|
|
bytesInDouble = struct.calcsize("d")
|
|
timeSent = struct.unpack("d", recPacket[28:28 + bytesInDouble])[0]
|
|
return timeReceived - timeSent
|
|
timeLeft = timeLeft - howLongInSelect
|
|
if timeLeft <= 0: return
|
|
|
|
def send_one_ping(my_socket, dest_addr, ID):
|
|
dest_addr = socket.gethostbyname(dest_addr)
|
|
my_checksum = 0
|
|
ICMP_ECHO_REQUEST = 8
|
|
header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, my_checksum, ID, 1) #压包
|
|
bytesInDouble = struct.calcsize("d")
|
|
data = (192 - bytesInDouble) * "Q"
|
|
data = struct.pack("d", time.time()) + data
|
|
my_checksum = checksum(header + data)
|
|
header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, socket.htons(my_checksum), ID, 1)
|
|
packet = header + data
|
|
my_socket.sendto(packet, (dest_addr, 1)) # Don't know about the 1
|
|
|
|
def do_one(dest_addr, timeout):
|
|
icmp = socket.getprotobyname("icmp")
|
|
try:
|
|
my_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)
|
|
except socket.error, (errno, msg):
|
|
if errno == 1:
|
|
msg = msg + (
|
|
" - Note that ICMP messages can only be sent from processes"
|
|
" running as root."
|
|
)
|
|
raise socket.error(msg)
|
|
raise # raise the original error
|
|
|
|
my_ID = os.getpid() & 0xFFFF
|
|
send_one_ping(my_socket, dest_addr, my_ID)
|
|
delay = receive_one_ping(my_socket, my_ID, timeout)
|
|
my_socket.close()
|
|
return delay
|
|
|
|
def get_ping(timeout = 0.5):
|
|
try:
|
|
delay = do_one(dest_addr, timeout)
|
|
except socket.gaierror, e:
|
|
return -2
|
|
|
|
if delay == None:
|
|
return -1
|
|
else:
|
|
delay = delay * 1000
|
|
return delay
|
|
|
|
if __name__ == '__main__':
|
|
print verbose_ping(sys.argv[1],2)
|