Skip to content

Commit 3cfdb01

Browse files
WillowSauceRWillowSauceR
authored andcommitted
support linux and other os
1 parent 0436485 commit 3cfdb01

File tree

6 files changed

+68
-25
lines changed

6 files changed

+68
-25
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
socks5.txt
2+
__pycache__/motd.cpython-37.pyc
3+
.gitignore
4+
t.py
5+
__pycache__/api.cpython-37.pyc

api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import socket
2+
import time
3+
4+
def getLocalHostIP():
5+
localHostIP = socket.gethostbyname(socket.gethostname())
6+
try:
7+
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
8+
s.connect(('8.8.8.8', 80))
9+
localHostIP = s.getsockname()[0]
10+
finally:
11+
s.close()
12+
return localHostIP
13+
14+
def getTime():
15+
return time.strftime('%H:%M:%S')

motd.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
from random import randint
2-
import socket, sys, time
2+
import socket
3+
import sys
4+
from api import getLocalHostIP, getTime
5+
localHostIP = getLocalHostIP()
36

4-
def getTime():
5-
return time.strftime('%H:%M:%S')
67

78
def sendPacket(ip, port):
89
sk_send = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
910
sk_send.settimeout(3)
10-
sk_send.bind((socket.gethostbyname(socket.gethostname()), randint(1024, 65535)))
11+
sk_send.bind((localHostIP, randint(1024, 65535)))
1112
sk_send.sendto(
1213
b'\x01\x00\x00\x00\x00$\r\x12\xd3\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x124Vx\n',
1314
(str(ip), int(port)))
1415
recvPacket(sk_send)
1516

17+
1618
def recvPacket(sk_send):
1719
data, addr = sk_send.recvfrom(10240)
1820
infos = []
@@ -39,9 +41,10 @@ def recvPacket(sk_send):
3941
except:
4042
print(f"[{getTime()}] Port info is unavailable.")
4143
print(f"[{getTime()}] Source: {addr[0]}:{addr[1]}")
42-
44+
4345
sk_send.close()
4446

47+
4548
if __name__ == "__main__":
4649
try:
4750
ip = sys.argv[1]
@@ -52,4 +55,5 @@ def recvPacket(sk_send):
5255
try:
5356
sendPacket(ip, port)
5457
except:
55-
print(f"[{getTime()}] Timeout! Server may be offline or blocked motd request.")
58+
print(
59+
f"[{getTime()}] Timeout! Server may be offline or blocked motd request.")

scan.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
from os import _exit
22
from random import randint
3-
import socket, threading, sys, time
3+
import socket
4+
import threading
5+
import sys
6+
import time
47
from scapy.all import *
8+
from api import getLocalHostIP
59

6-
localHostIP = socket.gethostbyname(socket.gethostname())
10+
localHostIP = getLocalHostIP()
711
localHostPort = randint(1024, 65535)
12+
813
try:
914
TargetAddr = str(sys.argv[1])
1015
except:
1116
TargetAddr = input("Target IP: ")
1217
motdData = b'\x01\x00\x00\x00\x00$\r\x12\xd3\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x124Vx\n'
1318
serverCount = 0
1419

20+
1521
def sendPacket(startNum, count):
1622
port = startNum
1723
while True:
@@ -76,17 +82,20 @@ def sendPacket(startNum, count):
7682
date = time.strftime('%H:%M:%S')
7783
if len(data) <= 30:
7884
skipped += 1
79-
print(f"[{date} R] data length <= 30, may not motd packet, skipped. Source: {addr[0]}:{addr[1]}")
85+
print(
86+
f"[{date} R] data length <= 30, may not motd packet, skipped. Source: {addr[0]}:{addr[1]}")
8087
continue
8188
if b"MCPE" not in data:
8289
skipped += 1
83-
print(f"[{date} R] metadata \"MCPE\" not in packet, may not motd packet, skipped. Source: {addr[0]}:{addr[1]}")
90+
print(
91+
f"[{date} R] metadata \"MCPE\" not in packet, may not motd packet, skipped. Source: {addr[0]}:{addr[1]}")
8492
continue
8593
if addr[1] not in payloads:
8694
payloads.append(addr[1])
8795
else:
8896
skipped += 1
89-
print(f"[{date} R] Duplicate server found, skipped. Source: {addr[0]}:{addr[1]}")
97+
print(
98+
f"[{date} R] Duplicate server found, skipped. Source: {addr[0]}:{addr[1]}")
9099
continue
91100
infos = []
92101
data1 = data.split(b"MCPE")
@@ -131,4 +140,3 @@ def sendPacket(startNum, count):
131140
print(f"[{time.strftime('%H:%M:%S')} R] An error occurred, skipped.")
132141
error += 1
133142
pass
134-

scanall.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
import socket, time
1+
import socket
2+
import time
3+
from api import getLocalHostIP
4+
5+
localHostIP = getLocalHostIP()
26

3-
localHostIP = socket.gethostbyname(socket.gethostname())
47

58
def sendPacket():
69
sk_send = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
710
sk_send.bind((localHostIP, 19132))
811
for a in range(256):
912
print(f"Scanning range: {str(a)}.0.0.0 ~ 255.255.255.255")
1013
for b in range(256):
11-
print(f"Scaning range: {str(a)}.{str(b)}.0.0 ~ {str(a)}.255.255.255")
14+
print(
15+
f"Scaning range: {str(a)}.{str(b)}.0.0 ~ {str(a)}.255.255.255")
1216
for c in range(256):
1317
#print(f"Scaning range: {str(a)}.{str(b)}.{str(c)}.0 ~ {str(a)}.{str(b)}.255.255")
1418
for d in range(256):
1519
try:
1620
IP = f"{str(a)}.{str(b)}.{str(c)}.{str(d)}"
1721
sk_send.sendto(
18-
b'\x01\x00\x00\x00\x00$\r\x12\xd3\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x124Vx\n',
19-
(IP, 19132))
22+
b'\x01\x00\x00\x00\x00$\r\x12\xd3\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x124Vx\n',
23+
(IP, 19132))
2024
except:
2125
continue
2226
sk_send.close()
@@ -36,5 +40,6 @@ def recPacket():
3640
except:
3741
pass
3842

43+
3944
sendPacket()
40-
# recPacket()
45+
# recPacket()

send.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import time
66
import os
7+
from api import getLocalHostIP, getTime
78

89
try:
910
import socks
@@ -12,13 +13,14 @@
1213
print("Import module error! Please run \"pip install -r requirements.txt\"")
1314
os._exit(1)
1415

15-
def getTime():
16-
return time.strftime('%H:%M:%S')
16+
localHostIP = getLocalHostIP()
17+
1718

1819
def getProxy() -> list:
1920
if not os.path.exists(r"socks5.txt"):
2021
print(f"[{getTime()}] Downloading proxy list...")
21-
wget.download("https://raw.githubusercontent.com/ShiftyTR/Proxy-List/master/socks5.txt")
22+
wget.download(
23+
"https://raw.githubusercontent.com/ShiftyTR/Proxy-List/master/socks5.txt")
2224
print(f"")
2325
print(f"[{getTime()}] Proxy list downloaded!")
2426

@@ -30,6 +32,7 @@ def getProxy() -> list:
3032
#print(proxyIP, ":", proxyPort)
3133
return proxyIP, int(proxyPort)
3234

35+
3336
def getOptions():
3437
try:
3538
target = sys.argv[1]
@@ -60,11 +63,12 @@ def getOptions():
6063
print()
6164
return target, int(port), file, int(loops), float(interval), proxyUsed, isDisplayMotd
6265

66+
6367
target, port, file, loops, interval, proxyUsed, isDisplayMotd = getOptions()
6468

69+
6570
def createSocket():
6671
localPort = random.randint(1024, 65535)
67-
localHostIP = socket.gethostbyname(socket.gethostname())
6872
proxyIP, proxyPort = None, None
6973
if proxyUsed:
7074
socketSend = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -77,6 +81,7 @@ def createSocket():
7781
socketSend.bind((str(localHostIP), localPort))
7882
return localPort, socketSend
7983

84+
8085
def sendPacket(target, port, file, loops, interval):
8186
for i in range(loops):
8287
try:
@@ -104,12 +109,14 @@ def sendPacket(target, port, file, loops, interval):
104109
else:
105110
for line in payloads:
106111
socketSend.sendto(line, (target, int(port)))
107-
print(f"[{getTime()}] Loop ", str(i)," done, used local port: ", str(localPort), "\n")
112+
print(f"[{getTime()}] Loop ", str(i),
113+
" done, used local port: ", str(localPort), "\n")
108114
except:
109-
print(f"[{getTime()}] Loop ", str(i)," error! Skip...", "\n")
115+
print(f"[{getTime()}] Loop ", str(i), " error! Skip...", "\n")
110116
pass
111117
if i+1 < loops:
112118
time.sleep(interval)
113119

120+
114121
if __name__ == "__main__":
115-
sendPacket(target, port, file, loops, interval)
122+
sendPacket(target, port, file, loops, interval)

0 commit comments

Comments
 (0)