This code work fine, every 5 second test the connection to this machine
(10.44.0.15) on my network.
# -*- coding: utf-8 -*-
#First: Testing connection
import socket, time
??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
??? output = testConn.connect_ex(('10.44.0.15', 80))
??? if output == 0:
??????? return True
??????? return False
??? if isInternet():
??? ??? print("Hay conexi?n")
??? ??? print("No hay conexi?n")
What's next?, I am all eyes
El 18/03/19 a las 12:44, Chris Angelico escribi?:
> On Tue, Mar 19, 2019 at 3:33 AM Informatico de Neurodesarrollo
> <infneurodcr.mtz at infomed.sld.cu> wrote:
>> Hello friends:
>> I am a beginner on programming in python.
> Cool! Then I would recommend making your program as simple as you possibly can.
>> I want make a simple program that test continuously (every 5 seg) the
>> connection to internet and change the background color when are not
>> available. I try this , but not work properly:
>> #!/usr/bin/env python3
>> # -*- coding: utf-8 -*-
>> from tkinter import *
>> import socket, time
>> def DetectarConexion():
>> testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
>> testConn.connect(('126.96.36.199', 80))
>> return True
>> return False
> This part of the code is completely independent of the Tkinter code.
> Split it up into the two parts and develop each one separately.
>> root = Tk()
>> while True:
>> if DetectarConexion():
>> # Background:Green
>> # Background:Red
> You have two separate parts to this code, and it's possible that
> neither of them is working. I would recommend concentrating first on
> the connection status function. Remove everything about Tkinter, and
> replace it with a simple print() call:
> while True:
> if DetectarConexion():
> print("Connection is happy")
> print("Connection is down!")
> Now you can work on making sure your connection tester is working.
> What exactly are you testing? What goes wrong when you don't have a
> Specific advice:
> 1) Avoid using the bare "except:" clause. It may be hiding bugs in your code.
> 2) Make sure you're trying something that actually does work.
> Connecting to 188.8.131.52 port 80 isn't going to succeed even if your
> connection is live.
> Start with that, and you should be able to get a lot further with your testing.
> Have fun with it! If you run into trouble, post your updated code,
> what you're trying, and what's happening.
> Chris Angelico
Ing. Jes?s Reyes Piedra
Admin Red Neurodesarrollo,C?rdenas
La caja dec?a:"Requiere windows 95 o superior"...
Entonces instal? LINUX.
Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas