Skip to main content
ALPHA    This is new software undergoing tests! Thank you for your patience.

Candidate: CHOY JIAN HAO jeffreychoy Presented by: Conrad Ho conrad Assessed by: Naomi Ceder nceder

Python (2023) ~ Grade 2 (Elementary)

The Force

to remote control my computer, via a website constructed by python code.

Attached files
Filename (click to download) Size Uploaded by
Django.png 95.6 KB jeffreychoy
Markdown code
![Django.png](/media/assessment/9009cf0d/2023-03-19/06-56-47/Django.png "Django.png")
WhatsApp_圖片_儲存時間_2023-03-2519.42.04.jpg 120.8 KB jeffreychoy
Markdown code
![...](/media/assessment/9009cf0d/2023-03-25/11-42-38/WhatsApp_%E5%9C%96%E7%89%87_%E5%84%B2%E5%AD%98%E6%99%82%E9%96%93_2023-03-2519.42.04.jpg "...")
key_erorr.png 21.0 KB jeffreychoy
Markdown code
![key_erorr.png](/media/assessment/9009cf0d/2023-04-11/11-14-09/key_erorr.png "key_erorr.png")
address.png 19.4 KB jeffreychoy
Markdown code
![address.png](/media/assessment/9009cf0d/2023-04-11/11-21-47/address.png "address.png")
ero.png 11.2 KB jeffreychoy
Markdown code
![ero.png](/media/assessment/9009cf0d/2023-04-11/11-26-24/ero.png "ero.png")
why.png 17.9 KB jeffreychoy
Markdown code
![why.png](/media/assessment/9009cf0d/2023-04-11/11-32-15/why.png "why.png")
是.png 83.9 KB jeffreychoy
Markdown code
![是.png](/media/assessment/9009cf0d/2023-05-05/09-56-11/%E6%98%AF.png "是.png")
WeChat_截圖_20230505175842.png 237.8 KB jeffreychoy
Markdown code
![WeChat_截圖_20230505175842.png](/media/assessment/9009cf0d/2023-05-05/09-58-52/WeChat_%E6%88%AA%E5%9C%96_20230505175842.png "WeChat_截圖_20230505175842.png")
WeChat_截圖_20230505180014.png 20.4 KB jeffreychoy
Markdown code
![WeChat_截圖_20230505180014.png](/media/assessment/9009cf0d/2023-05-05/10-00-21/WeChat_%E6%88%AA%E5%9C%96_20230505180014.png "WeChat_截圖_20230505180014.png")
1234444.jpg 128.5 KB jeffreychoy
Markdown code
![1234444.jpg](/media/assessment/9009cf0d/2023-05-10/10-18-07/1234444.jpg "1234444.jpg")
202305101841.mp4 7.0 MB jeffreychoy
Markdown code
[202305101841.mp4](/media/assessment/9009cf0d/2023-05-10/10-44-08/202305101841.mp4){target="_blank"}
202305101851.mp4 7.0 MB jeffreychoy
Markdown code
[202305101851.mp4](/media/assessment/9009cf0d/2023-05-10/10-53-51/202305101851.mp4){target="_blank"}

Status: Assessed (awaiting review).


jeffreychoy CHOY JIAN HAO ~ 24 Mar 2023 2:24 p.m.

Sometimes I will forget to shut down my computer before I leave home, and I do believe many people also face the same situation, and most of the remote control apps are either lagging or useless. Therefore I want to create a website, which can remotely control our computer while we are playing in Ocean park

To be honest, the reason that I want to create this web is just a simple answer. IT IS SO COOL. And I hope people can use it to do more meaningful things such as use it to help the elderly to fix their computers. (Because I have faced that situation before, and I have to go to my grandfather's house to help him:( .)


jeffreychoy CHOY JIAN HAO ~ 11 Apr 2023 10:51 a.m.

I want to use Python to connect two devices so the client can control the server device.

import socket
import os
import psutil

def send_data(data):
    os.system(data)
    print('[-][+][~]run order:[',data+']')

Database = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

info = psutil.net_if_addrs()
ips = []
for network_name in info:
    print(network_name)
    try:
        ip_info = info[network_name]  
    except:
        continue  
    for info in ip_info:
        if "." in info.address:
            ips.append(info.address)
print(ips)

it's the code that can get the addressinfo.


jeffreychoy CHOY JIAN HAO ~ 11 Apr 2023 11:11 a.m. (updated: 11 Apr 2023 11:28 a.m.)

what I want to say is before I ask my mentor about this code

info = psutil.net_if_addrs()
ips = []
for network_name in info:
    print(network_name)
    try:
        ip_info = info[network_name]  
    except:
        continue  
    for info in ip_info:
        if "." in info.address:
            ips.append(info.address)
print(ips)

THIS IS WHAT IT LOOKS LIKE

info = psutil.net_if_addrs()
wlan = info['WLAN']
def myaddr():
    for i in wlan:
        for myaddr in i:
            if '192.168' in str(myaddr):
                return myaddr

In the mentor session, I learned the method which is called magic(Jason said). TRY, EXCEPT. It's very useful I think, TRY TRY AND TRY.


jeffreychoy CHOY JIAN HAO ~ 11 Apr 2023 11:17 a.m.

The reason why I change this code is because this will happen. key_erorr.png So I fix this problem with my mentor Jason, After that I'm going to learn more about socket because socket can easily get the address of my computer, it's a powerful function.


jeffreychoy CHOY JIAN HAO ~ 11 Apr 2023 11:26 a.m. (updated: 11 Apr 2023 11:26 a.m.)

BIG PROBLEM

After getting the address like this.

address.png SOMETHING HAPPEN! What I want to do next is connecting the server

Database.bind (('ips[0]',7400))
Database.listen(1)
def main():
    while True:   
        try:      
            print(f'[#~]sever IP is[{ips[0]}]...')
            print('[#~]waiting for connection...')
            sed,dree=Database.accept()    
            print('[+]connected.')
            while True:
                if sed.recv(1024).decode('utf-8') == '':
                    break
                data = sed.recv(1024).decode('utf-8')
                send_data(data)   
        except:
            pass
        print('[-]disconnected..\n')

if __name__ == "__main__":
    main()

However, when I started debugging, it tells me that error happened:[Errno 11001] getaddrinfo failed ero.png


jeffreychoy CHOY JIAN HAO ~ 11 Apr 2023 11:29 a.m. (updated: 11 Apr 2023 11:31 a.m.)

I search for lots of info(https://stackoverflow.com/questions/7334199/getaddrinfo-failed-what-does-that-mean) and finally fix it, and another problem appears......

However, I think solving more and more upcoming problems is the pleasure of coding.


jeffreychoy CHOY JIAN HAO ~ 11 Apr 2023 11:32 a.m.

GOD......it happened again........ why.png


jeffreychoy CHOY JIAN HAO ~ 05 May 2023 9:49 a.m.

After five subjects of my DSE exam, I finally had time to deal with my project. But still struggling with the 'Socket error #11001: Host not found'.


jeffreychoy CHOY JIAN HAO ~ 05 May 2023 9:55 a.m.

Google is such a great search engine that can solve lots of problems. I discovered that https://www.remoteutilities.com/support/kb/socket-error-11001-host-not-found/ might help me deal with error #11001. For convenience, I will call it 'HNF' next time.


jeffreychoy CHOY JIAN HAO ~ 05 May 2023 9:58 a.m.

1.solve HNF

是.png so the first solution is not working, it seems like my server is having some problems.


jeffreychoy CHOY JIAN HAO ~ 05 May 2023 10 a.m.

WeChat_截圖_20230505175842.png I believe this might help me to walk the first step of solving the HNF.


jeffreychoy CHOY JIAN HAO ~ 05 May 2023 10:02 a.m.

WeChat_截圖_20230505180014.png Obviously, the ID server cannot be reached from the Host location, I need to contact my system administrator. BUT WHO IS THE SYSTEM ADMIN???


jeffreychoy CHOY JIAN HAO ~ 10 May 2023 10:18 a.m.

Finally, Finally, Finally, I finally fixed this problem, yesterday I was thinking what if I don't use 'e' to be the IP, and I noticed that I already have the address IP, so why don't I put that IP inside? AND THEN, THE ERROR DISAPPEARED!

def get_dns():
    domians = DataDispose.get_domain_list()
    for domian in domians:
        try:
            ips[0] = socket.getaddrinfo(domian[:-1],'http')
            print(ips)
        except Exception as e:
            print(e)
            continue
Database.bind (('26.32.223.195',8888));

I put 26.32.223.195 into it, this is my IP, so the IP in the socket should not be a character or String. 1234444.jpg


jeffreychoy CHOY JIAN HAO ~ 10 May 2023 10:44 a.m.

2. RUN THE PROGRAM

I made a short video to introduce how to connect two PC

202305101841.mp4


jeffreychoy CHOY JIAN HAO ~ 10 May 2023 10:46 a.m.

sever code

import socket
import os
import psutil

def send_data(data):
    os.system(data)
    print('[-][+][~]run order:[',data+']')

Database = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

info = psutil.net_if_addrs()
ips = []
for network_name in info:
    print(network_name)
    try:
        ip_info = info[network_name]  
    except:
        continue  
    for info in ip_info:
        if "." in info.address:
            ips.append(info.address)
print(ips)
def get_dns():
    domians = DataDispose.get_domain_list()
    for domian in domians:
        try:
            ips[0] = socket.getaddrinfo(domian[:-1],'http')
            print(ips)
        except Exception as e:
            print(e)
            continue
Database.bind (('26.32.223.195',8888));
Database.listen(1)
def main():
    while True:   
        try:      
            print(f'[#~]sever IP is[{ips[0]}]...')
            print('[#~]waiting for connection...')
            sed,dree=Database.accept()    
            print('[+]connected.')
            while True:
                if sed.recv(1024).decode('utf-8') == '':
                    break
                data = sed.recv(1024).decode('utf-8')
                send_data(data)   
        except:
            pass
        print('[-]disconnected..\n')

if __name__ == "__main__":
    main()

jeffreychoy CHOY JIAN HAO ~ 10 May 2023 10:47 a.m.

client code

import socket
udp_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
def main():
    while True:
        DATA = input('please input order:')
        if DATA == '':
            pass
        else:
            if len(DATA):
                udp_socket.send(DATA.encode('utf-8'))
                udp_socket.send(DATA.encode('utf-8'))
if __name__ == '__main__':
    myaddr = input('input sever IP:')
    udp_socket.connect((myaddr, 8888))  
    data_list = ''   
    udp_socket.send(data_list.encode('utf-8'))
    main()

jeffreychoy CHOY JIAN HAO ~ 10 May 2023 10:53 a.m. (updated: 10 May 2023 10:55 a.m.)

this video shows some commands that can do with the program 202305101851.mp4


jeffreychoy CHOY JIAN HAO ~ 10 May 2023 11:01 a.m.

I believe there are lot more that can be done in this project, for example, it can show the server screen to the client so that they will have a better user experience.


nceder Naomi Ceder ~ 28 Jul 2023 2:16 a.m. (updated: 28 Jul 2023 9:58 p.m.)

Hi,

I'll be assessing this project. First of all, this is a cool idea! Remote control always feels almost like magic, doesn't it?

As I look at and test your code, I have a few questions.

First of all, in the client program, you have:

        if DATA == '':
            pass
        else:
            if len(DATA):
                udp_socket.send(DATA.encode('utf-8'))
                udp_socket.send(DATA.encode('utf-8'))

Could you reword this so that you didn't have the else? That is, so that instead of checking for what you DON'T want and then doing the thing if it's false, checking for what you DO want and then doing the thing if it's true?

Second, you have the udp_socket.send twice. Why is that? What happens if it's there only once?

In the server code: You have a function get_dns() that is not used. In general, it's considered a code "smell" to have functions that aren't used. Do you need this?

You have:

        except:
            pass

in the main() function. What kinds of errors will that except catch? Can you think of any downside to catching all of these errors and then ignoring them?

And the last one for now, how do you expect the user to end the server program?

Cheers, Naomi


jeffreychoy CHOY JIAN HAO ~ 11 Aug 2023 10:34 a.m.

First of all, thank you for pointing out my mistake in coding, and I'm going through it. About the question NO.1, reword the if-else code. The following is the solution.

while True:
        DATA = input('please input order:')
        if DATA != '':
            if len(DATA):
                udp_socket.send(DATA.encode('utf-8'))
        pass

Second, the "twice python udp_socket.send "mistake was careless, so I corrected it immediately. In a nut shell, it is the solution about the client code.


jeffreychoy CHOY JIAN HAO ~ 11 Aug 2023 11:02 a.m.

For the sever code, I reword something so that the code will be make sense.

for network_name in info:
    print(network_name)
    try:
        ip_info = info[network_name]  
    except:
        continue  
    for info in ip_info:
        if "." in info.address:
            ips.append(info.address)
print(ips)
def ITLOOKSLIKEIREALLYDONTNEEDTHISBUTITSFUNSOILEAVEITHERE():
    domians = DataDispose.get_domain_list()
    for domian in domians:
        try:
            ips[0] = socket.getaddrinfo(domian[:-1],'http')
            print(ips)
        except Exception as e:
            print(e)
            continue
Database.bind (('26.32.223.195',8888));
Database.listen(1)

As for the python except: pass, this code is trying to catch the errors that happen in it

try:      
            print(f'[#~]sever IP is[{ips[0]}]...')
            print('[#~]waiting for connection...')
            sed,dree=Database.accept()    
            print('[+]connected.')
            while True:
                if sed.recv(1024).decode('utf-8') == '':
                    break
                data = sed.recv(1024).decode('utf-8')
                send_data(data)   
        except:
            pass

So one of the errors it will catch is if the server didn't receive the code that was input by the client, it will just ignore it, and wait for the next code. The downside is it might lag for the first code, client needs to code twice so that the server will get the command.


jeffreychoy CHOY JIAN HAO ~ 11 Aug 2023 11:05 a.m.

For the last question, if the user wants to end the program, they can just press the right top button. :)


nceder Naomi Ceder ~ 13 Aug 2023 2:26 a.m.

Well done on the fixes! A few more comments:


Back to top