Skip to content

Commit fd5d3df

Browse files
New checkpoint
1 parent 5a5f105 commit fd5d3df

File tree

10 files changed

+93
-0
lines changed

10 files changed

+93
-0
lines changed
298 KB
Loading
17 KB
Loading
39 KB
Loading

Networking/DiffieHellman/client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import random
2+
import socket
3+
4+
s = socket.socket()
5+
host = socket.gethostname()
6+
port = 8080
7+
8+
# constant's on client & server
9+
primeNumber = 13
10+
GeneratorP = 6
11+
12+
privateKey = 4
13+
publicKey = 9
14+
15+
x = str ( pow(GeneratorP,privateKey) % primeNumber )
16+
print('Generated key at client = {}'.format(x))
17+
s.connect((host, port))
18+
x = x.encode()
19+
s.send(x)
20+
recievedPublicKey = int(s.recv(1024).decode())
21+
print ('Recieved key from server = {}'.format(recievedPublicKey))
22+
decodedKey = pow(recievedPublicKey,privateKey) % primeNumber
23+
print('Shared secret client side = {}'.format(decodedKey))
24+
s.close()
25+
26+

Networking/DiffieHellman/server.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import random
2+
import socket
3+
4+
s = socket.socket()
5+
print(s)
6+
host = socket.gethostname()
7+
print(host)
8+
port = 8080
9+
10+
# constant's
11+
primeNumber = 13
12+
GeneratorP = 6
13+
14+
privateKey = 5
15+
publicKey = 2
16+
x = str ( pow(GeneratorP,privateKey) % primeNumber )
17+
print('Generated key at server = {}'.format(x))
18+
s.bind((host, port))
19+
s.listen(5)
20+
c, addr = s.accept()
21+
print ('Got connection from', addr)
22+
recievedPublicKey = int(c.recv(1024).decode())
23+
print ('Recieved key from client = {}'.format(recievedPublicKey))
24+
c.send(x.encode())
25+
# # sender server key
26+
decodedKey = pow(recievedPublicKey,privateKey) % primeNumber
27+
print('Shared secret client side = {}'.format(decodedKey))
28+
c.close()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os , sys , platform
2+
3+
class PortScanner:
4+
5+
def __init__(self):
6+
self.__sn = []
7+
if sys.platform == 'win32':
8+
self.__findCommand = 'netstat -ano | findstr :'
9+
self.__showActiveCommand = 'netstat -aon'
10+
elif sys.platform == 'linux' or sys.platform == 'linux2' :
11+
self.scanCommand = ''
12+
self.showActiveCommand = ''
13+
14+
def find(self,i):
15+
command = self.__findCommand + str(i)
16+
temp = os.popen(command).read()
17+
print(temp)
18+
19+
def showActive(self):
20+
temp = os.popen(self.__showActiveCommand).read()
21+
print(temp)
22+
23+
def close(self,i):
24+
command = self.__findCommand + str(i)
25+
temp = os.popen(command).read()
26+
if temp:
27+
pid = temp.split()[-1]
28+
print('Process id = {} '.format(pid))
29+
if sys.platform == 'win32':
30+
self.__taskKill = 'taskkill /PID '+ str(pid) +' /F'
31+
os.popen(self.__taskKill).read()
32+
33+
34+
if __name__ == "__main__":
35+
portScanner = PortScanner()
36+
# portScanner.showActive()
37+
# portScanner.find(8080)
38+
# portScanner.close(135)
39+

SocketPrograms/Thumbs.db

-10.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)