놀라운 파이썬 프로그램

Python을 사용한 인터넷 속도 테스트:




# Python program to test internet speed

import speedtest
st = speedtest.Speedtest()
option = int(input('''What speed do you want to test:
1) Download Speed
2) Upload Speed
3) Ping
Your Choice: '''))

if option == 1:
   print(st.download())
elif option == 2:
   print (st.upload())
elif option == 3:
   servernames = []
   st.get_servers(servernames)
   print (st.results.ping)
else:
   print("Please enter the correct choice !")


Python을 사용하여 모든 웹사이트 차단:




import time
from datetime import datetime as dt
hosts_path = "/etc/hosts"
redirect="127.0.0.1"
website_list =
["www.facebook.com", "facebook.com",
    "dub119.mail.live.com", "www.dub119.mail.live.com",
    "www.gmail.com", "gmail.com"]
while True:
    if dt(dt.now().year, dt.now().month, dt.now().day, 8)
    <dt.now() < dt(dt.now().year, dt.now().month, 
     dt.now().day, 16):
       print("Working hours...")
       with open(hosts_path, 'r+') as file:
           content=file.read()
           for website in website_list:
               if website in content:
                  pass
               else:
                   file.write(redirect website + "\n")
else:
    with open(hosts_path, 'r+') as file:
         content=file.readlines()
         file.seek (0)
         for line in content:
             if not any(website in line for website in 
website_list):
                file.write(line)
         file.truncate()
  print("Fun hours...")
time.sleep (5)


Python을 사용하여 시스템의 IP 주소를 얻으십시오.




# Python Program to Get IP Address

import socket
hostname = socket.gethostname()
IPAddr = socket.gethostbyname (hostname)
print("Your Computer Name is:" + hostname)
print("Your Computer IP Address is:" + IPAddr)

좋은 웹페이지 즐겨찾기