Re: Best way to check if there is internet?

2022-02-26 Thread Robert Latest via Python-list
Chris Angelico wrote:
> Every language learns from every other.

Except Visual Basic, which didn't learn anything from anywhere, and all that
can be learned from it is how not to do it. Ugh.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-26 Thread Peter J. Holzer
On 2022-02-22 12:31:42 +0400, Abdur-Rahmaan Janhangeer wrote:
> A front end eng sent me this for how to check for the internet in JS
> 
> https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-online
> 
> But it also says:
> 
> "This attribute is inherently unreliable. A computer can be connected to a
> network without having Internet access."

That actually checks whether the browser is in offline mode. You can set
this mode (in Firefox at least) via File -> Work offline. The browser
will also monitor network interfaces and switch to offline mode if none
(except loopback) are up. But fundamentally it's about the state of the
browser ("... must return false if the user agent will not contact the
network ...") not about whether your computer has "internet access" in
any meaningful sense.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Abdur-Rahmaan Janhangeer
> I never knew this. Where can I read more about this origin?

https://python-history.blogspot.com/2009/01/personal-history-part-1-cwi.html?m=1

<>


There are more sources which i cannot remember
from the top of my head
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Abdur-Rahmaan Janhangeer
Yes i know that JS has switch from before

I was referring to the pattern matching proposal.

I cannot find the original place i read it from but here's the github one

https://github.com/tc39/proposal-pattern-matching
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Greg Ewing

On 26/02/22 11:22 am, Chris Angelico wrote:

What's the best language for swearing in? Ah, that one I can't help
you with, although I've heard good things about French. :)


Russian seems to be quite good for it too, judging by
certain dashcam footage channels.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 09:04, Barry Scott  wrote:
>
>
>
> > On 25 Feb 2022, at 18:07, Abdur-Rahmaan Janhangeer  
> > wrote:
> >
> > Normally people put Python in the scripting category.
> > I learnt typed languages like C++ and Java at first.
> > People who learn languages like these tend to put
> > Python in a non-serious category. The post was
> > more ironic than litteral.
>
> I think that python is a serious language, as I do C and C++.
> What is key to a problem is which language is best to solve the
> problem (given you have a free choice).
>

Exactly. What language is best for a situation depends on myriad factors:

* Development convenience
* Execution performance
* Language/library tools
* Interaction with other parts of a system
* Corporate politics
* The ability to use other people's code
* Etcetera, etcetera, etcetera.

What's the best language for modding Kerbal Space Program? C#, because
ultimately, anything else will require a C# wrapper.

What's the best language for building a scientific simulation of
particle collisions? Probably something high level like Python, backed
by some hard number-crunching work in Fortran.

What's the best language for writing a browser-based game? JavaScript.

What's the best language for swearing in? Ah, that one I can't help
you with, although I've heard good things about French. :)

The only languages that are "not serious languages" in that sense are
deliberate toys. Chef, Piet, Whitespace, Ook, these are non-serious
languages that you shouldn't be writing production code in. Anything
else? If it's right for your purposes, use it, and don't let anyone
shame you for it.

There are almost no "right" and "wrong" design decisions. Your
decision has consequences, and if you accept those consequences, the
decision was not wrong.

Dismissing a mainstream language as "not serious" is, in effect,
telling everyone who uses that language "you're doing it wrong". And
that's an insult that should not be made lightly.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Barry Scott



> On 25 Feb 2022, at 18:07, Abdur-Rahmaan Janhangeer  
> wrote:
> 
> Normally people put Python in the scripting category.
> I learnt typed languages like C++ and Java at first.
> People who learn languages like these tend to put
> Python in a non-serious category. The post was
> more ironic than litteral.

I think that python is a serious language, as I do C and C++.
What is key to a problem is which language is best to solve the
problem (given you have a free choice).

My day job is writing and maintaining a large python application.
Python allows us to use best engineering technics.

Python is used because it out performs C/C++/etc in the speed that
we can implement new features and generate revenue from them.

> 
> After 5 years of following the mailing lists i realised
> that there is more than the eyes meet. My hobby has
> always been language engineering / compiler theory
> and just recently i realised that Python is pretty serious about
> language features.
> 
> I have been following language feature proposals from various
> languages. Some decide to avoid Python's route,
> but others have been trying hard to catch up with Python.
> One gleaming example is the switch case. JS recently proposed pattern
> matching, referencing Python and explaining why the proposal
> is a cool treatment of the usecase.
> 
> As a side note, if by scripting we mean OS commands,
> then Python started as a sysadmin language.

It was started as a research language to teach children programming.
Python's simplicity, that we benefit from to this day, comes from that original 
purpose.

And indeed one of the pleasures of the UK PYCON is seeing children present
their projects to a room full of adult programers. Seeing a 6 year old present 
their
working project is wonderful to behold.

Barry


> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Michael F. Stemper

On 25/02/2022 14.30, 2qdxy4rzwzuui...@potatochowder.com wrote:

On 2022-02-25 at 13:48:32 -0600,
"Michael F. Stemper"  wrote:


On 25/02/2022 12.07, Abdur-Rahmaan Janhangeer wrote:



I have been following language feature proposals from various
languages. Some decide to avoid Python's route, but others have been
trying hard to catch up with Python.  One gleaming example is the
switch case. JS recently proposed pattern matching, referencing
Python and explaining why the proposal is a cool treatment of the
usecase.



I'm not clear on what you mean here. JavaScript has had a switch/case
construct since 1.2, in the late 1990s. As far as I can determine,
python has no such thing, since PEP-3103 was rejected in 2007.


Python has a relatively new (as of version 3.10) "match" statement:

 https://docs.python.org/3/reference/compound_stmts.html#the-match-statement


Looks as if I have some reading to do. Thanks.


--
Michael F. Stemper
Always use apostrophe's and "quotation marks" properly.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 07:32, <2qdxy4rzwzuui...@potatochowder.com> wrote:
>
> On 2022-02-25 at 13:48:32 -0600,
> "Michael F. Stemper"  wrote:
>
> > On 25/02/2022 12.07, Abdur-Rahmaan Janhangeer wrote:
>
> > > I have been following language feature proposals from various
> > > languages. Some decide to avoid Python's route, but others have been
> > > trying hard to catch up with Python.  One gleaming example is the
> > > switch case. JS recently proposed pattern matching, referencing
> > > Python and explaining why the proposal is a cool treatment of the
> > > usecase.
>
> > I'm not clear on what you mean here. JavaScript has had a switch/case
> > construct since 1.2, in the late 1990s. As far as I can determine,
> > python has no such thing, since PEP-3103 was rejected in 2007.
>
> Python has a relatively new (as of version 3.10) "match" statement:
>
> 
> https://docs.python.org/3/reference/compound_stmts.html#the-match-statement

Every language learns from every other. Python has learned from
JavaScript too. Both languages have learned from Haskell. Pike has
learned from Python; and Python has learned from Pike. Nearly every
language learns from C and Smalltalk (sometimes indirectly). Of
course, not everything that is learned is copied - sometimes what you
learn is "let's not do it that way".

Python's match statement is not a switch/case block, and if JS is
borrowing the idea, then that's strong evidence that, even with
switch/case, match/case is a valuable addition. They behave very
differently in usage.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread 2QdxY4RzWzUUiLuE
On 2022-02-25 at 13:48:32 -0600,
"Michael F. Stemper"  wrote:

> On 25/02/2022 12.07, Abdur-Rahmaan Janhangeer wrote:

> > I have been following language feature proposals from various
> > languages. Some decide to avoid Python's route, but others have been
> > trying hard to catch up with Python.  One gleaming example is the
> > switch case. JS recently proposed pattern matching, referencing
> > Python and explaining why the proposal is a cool treatment of the
> > usecase.

> I'm not clear on what you mean here. JavaScript has had a switch/case
> construct since 1.2, in the late 1990s. As far as I can determine,
> python has no such thing, since PEP-3103 was rejected in 2007.

Python has a relatively new (as of version 3.10) "match" statement:

https://docs.python.org/3/reference/compound_stmts.html#the-match-statement
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Michael F. Stemper

On 25/02/2022 12.07, Abdur-Rahmaan Janhangeer wrote:


I have been following language feature proposals from various
languages. Some decide to avoid Python's route,
but others have been trying hard to catch up with Python.
One gleaming example is the switch case. JS recently proposed pattern
matching, referencing Python and explaining why the proposal
is a cool treatment of the usecase.


I'm not clear on what you mean here. JavaScript has had a
switch/case construct since 1.2, in the late 1990s. As far
as I can determine, python has no such thing, since PEP-3103
was rejected in 2007.


As a side note, if by scripting we mean OS commands,
then Python started as a sysadmin language.


I never knew this. Where can I read more about this origin?

--
Michael F. Stemper
If it isn't running programs and it isn't fusing atoms, it's just bending space.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 05:09, Abdur-Rahmaan Janhangeer
 wrote:
>
> Normally people put Python in the scripting category.

You have a very interesting definition of "normal".

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Abdur-Rahmaan Janhangeer
Normally people put Python in the scripting category.
I learnt typed languages like C++ and Java at first.
People who learn languages like these tend to put
Python in a non-serious category. The post was
more ironic than litteral.

After 5 years of following the mailing lists i realised
that there is more than the eyes meet. My hobby has
always been language engineering / compiler theory
and just recently i realised that Python is pretty serious about
language features.

I have been following language feature proposals from various
languages. Some decide to avoid Python's route,
but others have been trying hard to catch up with Python.
One gleaming example is the switch case. JS recently proposed pattern
matching, referencing Python and explaining why the proposal
is a cool treatment of the usecase.

As a side note, if by scripting we mean OS commands,
then Python started as a sysadmin language.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Benjamin Schollnick
>>> Thanks for the in-between. I really like the Python comunity as,
>>> even though it's a 'scripting' language,
> 
> And we like you, even though you're only a ...
> 
> In English, a statement like that is considered rather insulting.
> 
>> To me, it's a programming language. In my usage, a "script" is a
>> bunch of OS commands.
> 
> Exactly. A script is a set of commands that you would have normally
> entered by hand at a command prompt. But, after having gone through
> the process a few times, you decided to shove them into a file to save
> on typing.
> 
> Python is a programming language. Period.

Exactly.  In my opinion “It’s a scripting language”, is a devaluation of the 
language.
It’s an attempt to throw python in to a “trivial” classification.  

Heck, the same argument can be made of Bash, PHP, Perl, and a few other 
languages as well.

How many “scripts” have been throw quickly together in Perl, or PHP?  

Quite a damn few, yet, would anyone call Wordpress a “script”?

It’s effectively damning with faint praise.

- Benjamin


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Grant Edwards
On 2022-02-25, Michael F. Stemper  wrote:
> On 25/02/2022 06.49, Abdur-Rahmaan Janhangeer wrote:
>
>> Thanks for the in-between. I really like the Python comunity as,
>> even though it's a 'scripting' language,

And we like you, even though you're only a ...

In English, a statement like that is considered rather insulting.

> To me, it's a programming language. In my usage, a "script" is a
> bunch of OS commands.

Exactly. A script is a set of commands that you would have normally
entered by hand at a command prompt. But, after having gone through
the process a few times, you decided to shove them into a file to save
on typing.

Python is a programming language. Period.

[Yes, I know there's some sort of Python command interpreter intended
to be used for normal day-to-day use, but that's not what we're
talking about here.]

I classify some files that start with '#!/usr/bin/bash' as scripts,
but some are programs that just happen to be written in bash because
bash provides good facilities for doing filesystem manipulation and
running other executables.

I've never seen a Python program that I would consider a script.

But maybe that's just me...

--
Grant


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Michael F. Stemper

On 25/02/2022 06.49, Abdur-Rahmaan Janhangeer wrote:


Thanks for the in-between. I really like the Python comunity as,
even though it's a 'scripting' language,


To me, it's a programming language. In my usage, a "script" is
a bunch of OS commands.

--
Michael F. Stemper
Life's too important to take seriously.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-25 Thread Abdur-Rahmaan Janhangeer
Avi solved the captive portal problem above.
It's by comparing the page content to a dynamic
output.

I was asking for wifi just in case i missed
anything we did not yet discuss.

I consider the thread closed, thanks everybody,
it was very fruitful for me.

Thanks for the in-between. I really like the Python comunity as,
even though it's a 'scripting' language, the scrutiny
of issues and general discussions are currenly up to
a very nice level.

See you on another thread soon!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-23 Thread Robert Latest via Python-list
Abdur-Rahmaan Janhangeer wrote:
> I've got my answers but the 'wandering' a bit
> on this thread is at least connected to the topic ^^.
>
> Last question: If we check for wifi or ethernet cable connection?
>
> Wifi sometimes tell of connected but no internet connection.
> So it detected that there is or there is no internet ...

Your application obviously needs to make a certain network connection. Why
don't you just check if the connection can be made? Why would you care if it's
via cable or Wifi?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-23 Thread Robert Latest via Python-list
Abdur-Rahmaan Janhangeer wrote:
> Well, nice perspective.
>
> It's a valid consideration, sound theory
> but poor practicality according to me.

On the contrary: It is absolutely the right and only way to do it.

> It you view it like this then between the moment
> we press run or enter key on the terminal,
> our Python interpreter might get deleted.

Yeah, but by your logic you'd have to check the existence of /usr/bin/python
each time before you run it.

> Though it's nice to go in and catch exceptions,
> if you have a long operation upcoming it might be nice
> to see if your key element is present.

That is true, but you still must make sure that your long operation fails in a
controlled manner if the necessary ressource becomes unavailable in the
meantime.

> Checking by exceptions is what the snippet
> i shared does. But we check for the ability to do it
> before we start.

Nothing wrong with checking before.

> Of course, it can change in the seconds that follow. But it's too much pure
> logic at work.

No. It's the correct way of doing it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-23 Thread 2QdxY4RzWzUUiLuE
On 2022-02-23 at 09:28:40 -0700,
Akkana Peck  wrote:

> 2qdxy4rzwzuui...@potatochowder.com writes:
> > I think someone said it way upthread:  don't check, just do whatever you
> > came to do, and it will work or it will fail (presumably, your program
> > can tell the difference, regardless of a past snapshot of being able to
> > retrieve data from an arbitrary URL).
> > 
> > EAFP, anyone?
>
> Yes, but the code being discussed is still helpful, if only for
> error handling: yes, the network isn't fully up, but *why" isn't it?
>
> while True:
> try:
> do_whatever_I_came_to_do()
> except NetworkError:
> net_config_with_good_error_detection()

Sure, after the fact, once things fail, diagnostics are useful.  The
questions that remain are when should you run them, how complex do they
have to be, and how reliable can they be?

> Aside from error handling, it's useful in a network-up script:
> when you've just enabled a network, it's good to check right then if
> there's a captive portal and deal with it. If you just assume that
> the first thing the user wants is to go to an http: page in a
> browser, and so don't bother to check for a captive portal,
> that'll be annoying for people who want to fetch IMAP mail,
> or run ssh, or load an https: page.

Honest questions:  If I'm captured by a portal, do I "have internet"?
If I don't "have internet," who and/or what should detect, report,
and/or fix it?  When?

(As a matter of fact, I'm one of those people who annoyingly has to deal
with captive portals when my only use for the internet is IMAP or SMTP.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-23 Thread Chris Angelico
On Thu, 24 Feb 2022 at 03:39, Akkana Peck  wrote:
>
> 2qdxy4rzwzuui...@potatochowder.com writes:
> > I think someone said it way upthread:  don't check, just do whatever you
> > came to do, and it will work or it will fail (presumably, your program
> > can tell the difference, regardless of a past snapshot of being able to
> > retrieve data from an arbitrary URL).
> >
> > EAFP, anyone?
>
> Yes, but the code being discussed is still helpful, if only for
> error handling: yes, the network isn't fully up, but *why" isn't it?
>
> while True:
> try:
> do_whatever_I_came_to_do()
> except NetworkError:
> net_config_with_good_error_detection()

That's fair, although the NetworkError should at least be able to
distinguish between "no DNS server", "DNS server returned error",
"timeout connecting", "host not found", "network not found",
"connection refused", etc.

> Aside from error handling, it's useful in a network-up script:
> when you've just enabled a network, it's good to check right then if
> there's a captive portal and deal with it.

That's a little harder to recognize, since there are so many ways that
it can be done. Do all HTTP requests return 302 redirects? Do all
requests return a static HTML page? What do non-HTTP requests return?
I don't know that there's a generic way to recognize those kinds of
login screens.

> If you just assume that
> the first thing the user wants is to go to an http: page in a
> browser, and so don't bother to check for a captive portal,
> that'll be annoying for people who want to fetch IMAP mail,
> or run ssh, or load an https: page.

Agreed, it is annoying, especially when those logins time out after
fifteen minutes and force you to watch another ad before they let you
use the connection. But it's still extremely hard to recognize
reliably, so you'd probably end up coding something for the specific
portal that you are experienced with.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-23 Thread Akkana Peck
2qdxy4rzwzuui...@potatochowder.com writes:
> I think someone said it way upthread:  don't check, just do whatever you
> came to do, and it will work or it will fail (presumably, your program
> can tell the difference, regardless of a past snapshot of being able to
> retrieve data from an arbitrary URL).
> 
> EAFP, anyone?

Yes, but the code being discussed is still helpful, if only for
error handling: yes, the network isn't fully up, but *why" isn't it?

while True:
try:
do_whatever_I_came_to_do()
except NetworkError:
net_config_with_good_error_detection()

Aside from error handling, it's useful in a network-up script:
when you've just enabled a network, it's good to check right then if
there's a captive portal and deal with it. If you just assume that
the first thing the user wants is to go to an http: page in a
browser, and so don't bother to check for a captive portal,
that'll be annoying for people who want to fetch IMAP mail,
or run ssh, or load an https: page.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Dennis Lee Bieber
On Wed, 23 Feb 2022 07:08:27 +0300, Abdur-Rahmaan Janhangeer
 declaimed the following:


>The upcoming operation is short enough and
>though we cannot assume that it will be the case
>when we are running the operation, we sensibly
>assume it will still be the case.
>
>This is more an extra check to not start an operation than
>either relying to check at the start or when query.
>It's both.

So you have a success/fail tree of...

1   attempt a connection to some IP/port
1a  success -- attempt connection for desired operation
1a1 success -- operation completes
1a2 failure -- report that the operation can not be 
completed
1b  failure -- report that you will not attempt the operation
because your test connection to some site failed
EVEN IF THE OPERATION COULD SUCCEED
(if the problem is with "some IP/port", not
the rest of the network)

vs

1   attempt connection for desired operation
1a  success -- operation completes
1b  failure -- report that the operation cannot be completed

Personally the second tree is simpler -- AND NEEDS TO BE PART OF THE
OTHER TREE ANYWAY! [short tree 1/1a/1b are long tree 1a/1a1/1a2] The only
way the longer tree makes sense is by making step 1 a connection to the
IP/port requested in the desired operation -- and if that succeeds you've
basically performed the shorter tree.

>
>>


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Abdur-Rahmaan Janhangeer
>
> > Since you have to deal with things that you do not control changing
> after you check what is the point in checking? You have to write the code
> to recover anyway.
>


Well foe my usecase, the operation running is not
in months or a really long time. As Avi mentionned above,
that would be pointless.

The upcoming operation is short enough and
though we cannot assume that it will be the case
when we are running the operation, we sensibly
assume it will still be the case.

This is more an extra check to not start an operation than
either relying to check at the start or when query.
It's both.

>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Barry


> On 22 Feb 2022, at 17:44, Abdur-Rahmaan Janhangeer  
> wrote:
> 
> Well, nice perspective.
> 
> It's a valid consideration, sound theory
> but poor practicality according to me.
> 
> It you view it like this then between the moment
> we press run or enter key on the terminal,
> our Python interpreter might get deleted.

This is under your control usually so you do not need to check for python to be 
installed.
> 
> We never know, it can happen.
> 
> Though it's nice to go in and catch exceptions,
> if you have a long operation upcoming it might be nice
> to see if your key element is present.

You might check for enough disk space before starting to ensure that you can 
write the results, again this is usually under your control.

But you do not control the internet as an end user.
As it is not under your control you have to code to survive its failure modes.
For example email delivery is retried until the MTA gives up or succeeds.

> 
> Much like checking if goal posts are present before
> starting a football game. You can of course start
> the match, pass the ball around and when shooting
> you stop the match as you realise that the goal posts
> are not around.

Check before you start. But you are going to notice people attempting to take 
goal posts away while you play.

> Checking by exceptions is what the snippet
> i shared does. But we check for the ability to do it
> before we start.
> 
> Of course, it can change in the seconds that follow. But it's too much pure
> logic at work.

Since you have to deal with things that you do not control changing after you 
check what is the point in checking? You have to write the code to recover 
anyway.

Barry

> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Abdur-Rahmaan Janhangeer
I've got my answers but the 'wandering' a bit
on this thread is at least connected to the topic ^^.

Last question: If we check for wifi or ethernet cable connection?

Wifi sometimes tell of connected but no internet connection.
So it detected that there is or there is no internet ...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Chris Angelico
On Wed, 23 Feb 2022 at 05:38, Avi Gross via Python-list
 wrote:
> It sounds to me like your main issue is not whether the internet is up right 
> now but whether the user has an internet connection. If they run the program 
> on a laptop at home or work then they may well be connected, but sitting in 
> their car in some parking lot, may well not be.
>

Very seldom, a computer actually has *no* network connection. Much
more often, you have a network connection, but it's not very useful.
For example, you might have full network connectivity... but only on
localhost. Or you might be on a LAN, and fully able to access its
resources, but your uplink to the rest of the internet is down. Or
maybe you're a server inside Facebook, and the rest of the internet is
slowly getting disconnected from you. Do you have an internet
connection? Do you have what you need?

*There is no way* to answer the question of whether you have internet
access, other than to try the exact thing you want to do, and see if
it fails. People who think that there's a binary state of "have
internet" // "do not have internet" have clearly never worked in
networking

(No, I've never accidentally misconfigured a network so that we had
full access to everything *except* the local network. Why do you ask?
Anyway, I fixed it within a few minutes.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Avi Gross via Python-list
As usual, his discussion is wandering a bit.

Yes, some things are not reliable but sometimes a heuristic answer is better 
than none.

Internet connections are beyond flaky and worse the connection you want may be 
blocked for many reasons even if other connections you try are working. Any 
number of routers can lose power or you personally may be blocked by something 
if they deem the place you want unsafe and much more.

In Statistics, you often work not with TRUE and FALSE but with ranges of 
probability and you may deem something as tentatively true if it is 95% or 99% 
likely it did not happen by chance given your sample.

But for a long-running program, checking if the internet is up ONCE is clearly 
not good enough if it runs for months at a time. Checking right before making a 
connection may be a bit much too.

But computers often spend a majority of their time doing things like checking. 
If I am using a GUI and the process is waiting to see if I type some key (or 
even am depressing the Shift key which normally does not generate any symbols 
by itself) and also testing if my mouse is moving or has moved over an area or 
one of several buttons has been clicked, then what may be happening is 
something in a loop that keeps checking and when an event has happened, 
notifies something to continue and perhaps provides the results. Something 
along those lines can happen when say a region of memory/data is being shared 
and one part wants to know if the memory is still locked or has finally been 
written to by another part and can be read and so on.

For something important, it is not enough to check if a file system is mounted 
and available and then write the file and move on. You may want to not only 
test the exit status of the write, or arrange to catch exceptions, but to then 
re-open the file and read in what you wrote and verify that it seems correct. 
In some cases, you get even more paranoid and save some kind of log entry that 
can be used to recreate the scenario if something bad happens and store that in 
another location in case there is a fire or something. 

So the answer is that it is up to you to decide how much effort is warranted. 
Can you just try a connection and react if it fails or must you at least get a 
decent guess that there is an internet connection of some kind up and running 
or must it be ever more bulletproof?

A scenario might be one where you are providing info and can adjust depending 
on various settings. If the user has an internet connection on, you can use 
video and graphics and so on that result in something current. But if they have 
settings suggesting they want to minimize the data they send and receive, the 
same request may result in the browser you invoked showing them just some 
alternative text. You have no way of knowing. Again, if the internet is not up, 
you may just present your own canned text, perhaps dated. Or, you can suggest 
to the user they turn on the internet and try again, or ...

It sounds to me like your main issue is not whether the internet is up right 
now but whether the user has an internet connection. If they run the program on 
a laptop at home or work then they may well be connected, but sitting in their 
car in some parking lot, may well not be.




-Original Message-
From: Abdur-Rahmaan Janhangeer 
To: Python 
Sent: Tue, Feb 22, 2022 12:32 pm
Subject: Re: Best way to check if there is internet?


Well, nice perspective.

It's a valid consideration, sound theory
but poor practicality according to me.

It you view it like this then between the moment
we press run or enter key on the terminal,
our Python interpreter might get deleted.

We never know, it can happen.

Though it's nice to go in and catch exceptions,
if you have a long operation upcoming it might be nice
to see if your key element is present.

Much like checking if goal posts are present before
starting a football game. You can of course start
the match, pass the ball around and when shooting
you stop the match as you realise that the goal posts
are not around.

Checking by exceptions is what the snippet
i shared does. But we check for the ability to do it
before we start.

Of course, it can change in the seconds that follow. But it's too much pure
logic at work.

-- 
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Abdur-Rahmaan Janhangeer
Well, nice perspective.

It's a valid consideration, sound theory
but poor practicality according to me.

It you view it like this then between the moment
we press run or enter key on the terminal,
our Python interpreter might get deleted.

We never know, it can happen.

Though it's nice to go in and catch exceptions,
if you have a long operation upcoming it might be nice
to see if your key element is present.

Much like checking if goal posts are present before
starting a football game. You can of course start
the match, pass the ball around and when shooting
you stop the match as you realise that the goal posts
are not around.

Checking by exceptions is what the snippet
i shared does. But we check for the ability to do it
before we start.

Of course, it can change in the seconds that follow. But it's too much pure
logic at work.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread 2QdxY4RzWzUUiLuE
On 2022-02-09 at 11:15:34 +0400,
Abdur-Rahmaan Janhangeer  wrote:

> I think for me having the internet means ability to request urls

You can always ask.

The real question is what will the response be?  ;-)

This entire exercise is a race condition, just like checking for that a
file exists before deleting it, or that it doesn't exist before creating
it.

If you "have internet" when you check, what assurance do you have that
you will still "have internet" when you actually want to use it?

And if you don't "have internet" when you check, when do you check
again?

I think someone said it way upthread:  don't check, just do whatever you
came to do, and it will work or it will fail (presumably, your program
can tell the difference, regardless of a past snapshot of being able to
retrieve data from an arbitrary URL).

EAFP, anyone?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Chris Angelico
On Wed, 23 Feb 2022 at 02:33, Chris Green  wrote:
>
> Chris Angelico  wrote:
> > On Tue, 22 Feb 2022 at 19:33, Abdur-Rahmaan Janhangeer
> >  wrote:
> > >
> > > As discussed here but, it would have been nevertheless great to have this
> > > tiny function instead of
> > > nothing
> > >
> >
> > Here's a function that determines whether or not you have an internet
> > connection. It's almost as reliable as some of the other examples
> > given - I know this, because I tried it ten times, and it gave the
> > correct result every time!
> >
> > def has_internet():
> > return True
> >
> > Tell me, is it useful to have something that doesn't always give the
> > right answer, even if it usually does? Is there any value whatsoever
> > in a lie?
> >
> That's sort of in the same area as a stopped clock being right more
> often than one that runs just a bit slow (or fast).  :-)
>

Oddly enough, if your options for clocks are "right twice a day",
"right once a week", "right once a month", and "never right", the most
useful is probably actually the one that's never right, because if it
ticks at the right rate but is set slightly wrong, it'll always be
exactly that same offset away from correct (which you can adjust for).

But a function to tell you whether you have the internet or not is
like a clock that tells you whether you have time or not. In a
technical (and vacuous) sense, yes, you do... in a practical and
useful sense, who knows?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Chris Green
Chris Angelico  wrote:
> On Tue, 22 Feb 2022 at 19:33, Abdur-Rahmaan Janhangeer
>  wrote:
> >
> > As discussed here but, it would have been nevertheless great to have this
> > tiny function instead of
> > nothing
> >
> 
> Here's a function that determines whether or not you have an internet
> connection. It's almost as reliable as some of the other examples
> given - I know this, because I tried it ten times, and it gave the
> correct result every time!
> 
> def has_internet():
> return True
> 
> Tell me, is it useful to have something that doesn't always give the
> right answer, even if it usually does? Is there any value whatsoever
> in a lie?
> 
That's sort of in the same area as a stopped clock being right more
often than one that runs just a bit slow (or fast).  :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Chris Angelico
On Wed, 23 Feb 2022 at 01:06, Antoon Pardon  wrote:
>
>
> Op 22/02/2022 om 09:40 schreef Chris Angelico:
> > On Tue, 22 Feb 2022 at 19:33, Abdur-Rahmaan Janhangeer
> >   wrote:
> >> As discussed here but, it would have been nevertheless great to have this
> >> tiny function instead of
> >> nothing
> >>
> > Here's a function that determines whether or not you have an internet
> > connection. It's almost as reliable as some of the other examples
> > given - I know this, because I tried it ten times, and it gave the
> > correct result every time!
>
> So, you discovered a way of testing that is not very thorough.
>
> > def has_internet():
> >  return True
> >
> > Tell me, is it useful to have something that doesn't always give the
> > right answer, even if it usually does? Is there any value whatsoever
> > in a lie?
>
> Yes that is useful. Live is full of that kind of situations. We in 
> computerland
> are spoiled with the accuracy we can enjoy. It seems even spoiled to the 
> extend
> that when offered a solution that is not 100% accurated we consider it a lie.
>

Cool! Then you have a very useful internet-availability testing
function. Have fun!

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Antoon Pardon



Op 22/02/2022 om 09:40 schreef Chris Angelico:

On Tue, 22 Feb 2022 at 19:33, Abdur-Rahmaan Janhangeer
  wrote:

As discussed here but, it would have been nevertheless great to have this
tiny function instead of
nothing


Here's a function that determines whether or not you have an internet
connection. It's almost as reliable as some of the other examples
given - I know this, because I tried it ten times, and it gave the
correct result every time!


So, you discovered a way of testing that is not very thorough.


def has_internet():
 return True

Tell me, is it useful to have something that doesn't always give the
right answer, even if it usually does? Is there any value whatsoever
in a lie?


Yes that is useful. Live is full of that kind of situations. We in computerland
are spoiled with the accuracy we can enjoy. It seems even spoiled to the extend
that when offered a solution that is not 100% accurated we consider it a lie.

--
Antoon.
--
https://mail.python.org/mailman/listinfo/python-list


Aw: Re: Best way to check if there is internet?

2022-02-22 Thread Karsten Hilbert
> Is there any value whatsoever in a lie?

Do we _know_ it's a lie ?

Does a lie become a Falsed Truth once it becomes known ?

Karsten

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Abdur-Rahmaan Janhangeer
Thanks for the function but i think having the function
as described won't return True all time

Me: dipping my foot in hot water, yes we can go ...

In the sprit of "practicality beats purity", devs needs a function
XD

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Chris Angelico
On Tue, 22 Feb 2022 at 19:40, Chris Angelico  wrote:
>
> On Tue, 22 Feb 2022 at 19:33, Abdur-Rahmaan Janhangeer
>  wrote:
> >
> > As discussed here but, it would have been nevertheless great to have this
> > tiny function instead of
> > nothing
> >
>
> Here's a function that determines whether or not you have an internet
> connection. It's almost as reliable as some of the other examples
> given - I know this, because I tried it ten times, and it gave the
> correct result every time!
>
> def has_internet():
> return True
>
> Tell me, is it useful to have something that doesn't always give the
> right answer, even if it usually does? Is there any value whatsoever
> in a lie?

Obligatory XKCD:

https://xkcd.com/937/

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Chris Angelico
On Tue, 22 Feb 2022 at 19:33, Abdur-Rahmaan Janhangeer
 wrote:
>
> As discussed here but, it would have been nevertheless great to have this
> tiny function instead of
> nothing
>

Here's a function that determines whether or not you have an internet
connection. It's almost as reliable as some of the other examples
given - I know this, because I tried it ten times, and it gave the
correct result every time!

def has_internet():
return True

Tell me, is it useful to have something that doesn't always give the
right answer, even if it usually does? Is there any value whatsoever
in a lie?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-22 Thread Abdur-Rahmaan Janhangeer
A front end eng sent me this for how to check for the internet in JS

https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-online

But it also says:

"This attribute is inherently unreliable. A computer can be connected to a
network without having Internet access."

As discussed here but, it would have been nevertheless great to have this
tiny function instead of
nothing

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius


On Mon, Feb 7, 2022 at 1:17 PM Abdur-Rahmaan Janhangeer <
arj.pyt...@gmail.com> wrote:

> Greetings,
>
> Using the standard library or 3rd party libraries, what's the
> best way to check if there is internet? Checking if google.com
> is reachable is good but I wonder if there is a more native,
> protocol-oriented
> way of knowing?
>
> Even this URL recommends checking if a domain is up as a way to check for
> internet connectivity:
>
> https://www.ibm.com/support/pages/checking-network-connectivity-when-using-python-and-ibm-resilient-circuits
>
> Kind Regards,
>
> Abdur-Rahmaan Janhangeer
> about  | blog
> 
> github 
> Mauritius
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-09 Thread Avi Gross via Python-list
Actually, you may want a dynamic page. Pages may sometimes be delivered from 
some cache along the way perhaps within your own company firewall if someone 
else recently accessed them.
Consider a page that returns the current time or like the following asks for an 
arithmetical calculation to add 5 and 6
https://search.yahoo.com/search?fr=mcafee&type=E211US1249G0&p=%3D5%2B6
Not a great example, and it may not work for you, but there likely is a site 
that can exist that accepts a request for some formatted calculation that you 
can specify dynamically. You can compare a date/time returned to being accurate 
within some seconds and asking for n*m can obviously be validated.
Of course, once such a ploy is well known, it can be intercepted and sent 
proper results and still fool you into assuming you had full internet access. 
So a site that you can send to and receive back using a cryptographic method 
might be better.



-Original Message-
From: Abdur-Rahmaan Janhangeer 
To: Python 
Sent: Wed, Feb 9, 2022 12:24 pm
Subject: Re: Best way to check if there is internet?

> This won't work if you're behind a captive portal: every URL you
try to get will return successfully, but the content will be
the captive portal page.

Yes agree a pretty common scenario if you are moving around ...
The solution is to test against a webpage you know the content
will always be the same. Thanks for pointing out!

Kind Regards,

Abdur-Rahmaan Janhangeer
about <https://compileralchemy.github.io/> | blog
<https://www.pythonkitchen.com>
github <https://github.com/Abdur-RahmaanJ>
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-09 Thread Abdur-Rahmaan Janhangeer
> This won't work if you're behind a captive portal: every URL you
try to get will return successfully, but the content will be
the captive portal page.

Yes agree a pretty common scenario if you are moving around ...
The solution is to test against a webpage you know the content
will always be the same. Thanks for pointing out!

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-09 Thread Abdur-Rahmaan Janhangeer
>  Ah, but WHEN do those browsers report that? When attempting to connect
to whatever the default "home" page has been set to? (Mine is configured to
use https://www.google.com as the default page -- if my router is down,
obviously the browser will time-out waiting for a response from Google, and
report "no network").

Yes you are right ... lol i misread the error i guess

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-09 Thread Akkana Peck
Abdur-Rahmaan Janhangeer writes:
> results = []
> with console.status("Checking internet ...", spinner="dots"):
> for domain in domains:
> try:
> requests.get(domain)
> results.append(1)
> except Exception as e:
> results.append(0)
> if not any(results):
> print('No internet connection')
> sys.exit()
> 
> gist link:
> https://gist.github.com/Abdur-rahmaanJ/7917dc5ab7f5d2aa37b2723909be08f7
> 
> I think for me having the internet means ability to request urls

Request urls and get the right answer?

This won't work if you're behind a captive portal: every URL you
try to get will return successfully, but the content will be
the captive portal page.

You need to compare the output of at least one of those pages to
known output to be sure you're really connected.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-09 Thread Gisle Vanem

Abdur-Rahmaan Janhangeer wrote:


It's a demo to get the idea behind, uses requests and the rich library.


I'd never heard of 'Rich'. But d/l it and playing
with it, I came up with this version with fat green
spinner-bar:

import requests
from rich.console import Console

def ensure_internet():
console = Console()
domains = [ "https://google.com";,
"https://yahoo.com";,
"https://bing.com";,
"https://www.ecosia.org";,
"https://www.wikipedia.org"; ]
results = []
with console.status ("Checking internet ...", spinner="material") as c:
for domain in domains:
c._spinner.text = "Checking %-40s" % domain
try:
requests.get(domain)
results.append(1)
except Exception as e:
results.append(0)

if not any(results):
   print("No internet connection")

ensure_internet()

---

Rich' is IMO a pretty amazing package.

--gv
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-09 Thread Abdur-Rahmaan Janhangeer
It's a demo to get the idea behind, uses requests and the rich library.

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius


On Wed, Feb 9, 2022 at 12:24 PM Gisle Vanem  wrote:

> Abdur-Rahmaan Janhangeer wrote:
>
> > Thanks everybody for the answers. It was very enlightening. Here's my
> > solution:
> >
> > # using rich console
> > def ensure_internet():
> > console = Console()
> > domains = [
> > 'https://google.com',
> > 'https://yahoo.com',
> > 'https://bing.com',
> > 'https://www.ecosia.org',
> > 'https://www.wikipedia.org'
> > ]
> > results = []
> > with console.status("Checking internet ...", spinner="dots"):
> > for domain in domains:
> > try:
> > requests.get(domain)
> > results.append(1)
> > except Exception as e:
> > results.append(0)
> > if not any(results):
> > print('No internet connection')
> > sys.exit()
>
> Was this supposed to be a self-contained working
> program? It doesn't work here.
>
> Were/what is 'Console()' for example?
>
> --
> --gv
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-09 Thread Gisle Vanem

Abdur-Rahmaan Janhangeer wrote:


Thanks everybody for the answers. It was very enlightening. Here's my
solution:

# using rich console
def ensure_internet():
console = Console()
domains = [
'https://google.com',
'https://yahoo.com',
'https://bing.com',
'https://www.ecosia.org',
'https://www.wikipedia.org'
]
results = []
with console.status("Checking internet ...", spinner="dots"):
for domain in domains:
try:
requests.get(domain)
results.append(1)
except Exception as e:
results.append(0)
if not any(results):
print('No internet connection')
sys.exit()


Was this supposed to be a self-contained working
program? It doesn't work here.

Were/what is 'Console()' for example?

--
--gv
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-08 Thread Abdur-Rahmaan Janhangeer
Thanks everybody for the answers. It was very enlightening. Here's my
solution:

# using rich console
def ensure_internet():
console = Console()
domains = [
'https://google.com',
'https://yahoo.com',
'https://bing.com',
'https://www.ecosia.org',
'https://www.wikipedia.org'
]
results = []
with console.status("Checking internet ...", spinner="dots"):
for domain in domains:
try:
requests.get(domain)
results.append(1)
except Exception as e:
results.append(0)
if not any(results):
print('No internet connection')
sys.exit()

gist link:
https://gist.github.com/Abdur-rahmaanJ/7917dc5ab7f5d2aa37b2723909be08f7

I think for me having the internet means ability to request urls

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-08 Thread Alan Bawden
And I missed one that was just published last month:

https://datatracker.ietf.org/doc/html/rfc9171

Unlike RFC 5050, this version of the protocol actually claims to be a
"Proposed Standard".

-- 
Alan Bawden
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-08 Thread Alan Bawden
Greg Ewing  writes:

   On 8/02/22 8:51 am, Chris Angelico wrote:
   > Some day, we'll have people on Mars. They won't have TCP connections -
   > at least, not unless servers start supporting connection timeouts
   > measured in minutes or hours - but it wouldn't surprise me if some
   > sort of caching proxy system is deployed.

   Or the internet acquires a new protocol that's designed
   for very-long-latency connections.

Very much a hot topic:

https://www.nasa.gov/directorates/heo/scan/engineering/technology/disruption_tolerant_networking_overview
https://en.wikipedia.org/wiki/Delay-tolerant_networking
https://datatracker.ietf.org/doc/html/rfc4838
https://datatracker.ietf.org/doc/html/rfc5050

-- 
Alan Bawden
-- 
https://mail.python.org/mailman/listinfo/python-list


Aw: Re: Best way to check if there is internet?

2022-02-07 Thread Karsten Hilbert
> Or the internet acquires a new protocol that's designed
> for very-long-latency connections.

That's being worked on already

https://en.wikipedia.org/wiki/NASA_Deep_Space_Network

Karsten
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Chris Angelico
On Tue, 8 Feb 2022 at 12:20, Ethan Furman  wrote:
>
> On 2/7/22 4:27 PM, Greg Ewing wrote:
>  > On 8/02/22 8:51 am, Chris Angelico wrote:
>
>  >> Some day, we'll have people on Mars. They won't have TCP connections -
>  >> at least, not unless servers start supporting connection timeouts
>  >> measured in minutes or hours - but it wouldn't surprise me if some
>  >> sort of caching proxy system is deployed.
>  >
>  > Or the internet acquires a new protocol that's designed
>  > for very-long-latency connections.
>
> RocketNet -- a massive store-and-forward protocol.  ;-)
>

Definitely possible. Though wouldn't a rocket scientist call it
"store-and-prograde"? :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Michael Torrie
On 2/7/22 12:51, Chris Angelico wrote:
> Some day, we'll have people on Mars. They won't have TCP connections -
> at least, not unless servers start supporting connection timeouts
> measured in minutes or hours - but it wouldn't surprise me if some
> sort of caching proxy system is deployed.
> 
> On the other hand, it also wouldn't surprise me if we do everything at
> a high level instead - have a Martian PyPI mirror, Debian package
> mirror, etc, etc, etc - and then build a mirror synchronization
> protocol that uses UDP.
> 
> Either way, though: would a person on Mars "have the internet"? Yes,
> but not the internet as we know it...

Fun fact.  The team running the Ingenuity helicopter on mars has shell
access to Linux running on the copter.  Obviously not interactive in the
normal sense of course, but they can batch shell commands and pass them
through the communication network to the rover, which relays them to the
copter.  Standard out is relayed back to earth at the next opportunity.
 Currently they use this remote shell access to compress all the images
after each flight and use ffmpeg to create video sequences from stills
on the copter computer itself.  They also used it to do some hacks to
temporarily fix the watchdog timing issue they had initially.  One of
the Linux gurus on the project has given several interviews to the Linux
Unplugged podcast. Fastinating stuff!

It's likely they have a python interpreter onboard as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Ethan Furman

On 2/7/22 4:27 PM, Greg Ewing wrote:
> On 8/02/22 8:51 am, Chris Angelico wrote:

>> Some day, we'll have people on Mars. They won't have TCP connections -
>> at least, not unless servers start supporting connection timeouts
>> measured in minutes or hours - but it wouldn't surprise me if some
>> sort of caching proxy system is deployed.
>
> Or the internet acquires a new protocol that's designed
> for very-long-latency connections.

RocketNet -- a massive store-and-forward protocol.  ;-)

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Greg Ewing

On 8/02/22 8:51 am, Chris Angelico wrote:

Some day, we'll have people on Mars. They won't have TCP connections -
at least, not unless servers start supporting connection timeouts
measured in minutes or hours - but it wouldn't surprise me if some
sort of caching proxy system is deployed.


Or the internet acquires a new protocol that's designed
for very-long-latency connections.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Chris Angelico
On Tue, 8 Feb 2022 at 09:31, <2qdxy4rzwzuui...@potatochowder.com> wrote:
>
> On 2022-02-08 at 06:51:20 +1100,
> Chris Angelico  wrote:
>
> > Either way, though: would a person on Mars "have the internet"? Yes,
> > but not the internet as we know it...
>
> By current definition, they *can't* have the internet as we know it.
>
> Wikipedia,¹ Mirrian-Webster,² and TechTerms.com³ (the first three that
> came up in my search engine, which is admittedly Earthbound for now) all
> use words like "global" and phrases like "across the world" or "around
> the world," all of which arguably exclude Mars, or at least a network
> that covers both Earth and Mars.
>

Yes, well, globally-unique IDs are probably going to be
universally-unique IDs too, but we're not hugely bothered by that.
Remember, you can get targeted advertising on the ISS too...

https://xkcd.com/713/

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread 2QdxY4RzWzUUiLuE
On 2022-02-08 at 06:51:20 +1100,
Chris Angelico  wrote:

> Either way, though: would a person on Mars "have the internet"? Yes,
> but not the internet as we know it...

By current definition, they *can't* have the internet as we know it.

Wikipedia,¹ Mirrian-Webster,² and TechTerms.com³ (the first three that
came up in my search engine, which is admittedly Earthbound for now) all
use words like "global" and phrases like "across the world" or "around
the world," all of which arguably exclude Mars, or at least a network
that covers both Earth and Mars.

IMO, Mars and its current and future living beings are better off
without the World Wide Web, too.

¹ https://en.wikipedia.org/wiki/Internet
² https://www.merriam-webster.com/dictionary/Internet
³ https://techterms.com/definition/internet
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Chris Angelico
On Tue, 8 Feb 2022 at 08:30, Cameron Simpson  wrote:
>
> On 08Feb2022 06:51, Chris Angelico  wrote:
> >Some day, we'll have people on Mars. They won't have TCP connections -
> >at least, not unless servers start supporting connection timeouts
> >measured in minutes or hours - but it wouldn't surprise me if some
> >sort of caching proxy system is deployed.
>
> The TCP ESTABLISHED state has no timeouts at all (though intemediate
> stateful things can get bored).  The setup/teardown do though :-)

That's what I mean - not a lot of point trying to establish a TCP
socket if the other end will give up on you after a mere ninety
seconds. It's extremely convenient that an established connection
lasts forever until touched in some way (even across reconfigurations
of the network - which is how you can redo a server's network over
SSH), but first you have to get to that!

> But
> they can be proxied. Our previous satellite modem proxied TCP locally
> and ran a more-suitable-satellite protocol from the modem to the
> downstation, where it became TCP again and went on its way.

Yup. I'm not sure whether we'll proxy TCP, proxy HTTP, or have high
level mirrors, but one way or another, people on Mars will want their
internets plsthx.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Cameron Simpson
On 08Feb2022 06:51, Chris Angelico  wrote:
>Some day, we'll have people on Mars. They won't have TCP connections -
>at least, not unless servers start supporting connection timeouts
>measured in minutes or hours - but it wouldn't surprise me if some
>sort of caching proxy system is deployed.

The TCP ESTABLISHED state has no timeouts at all (though intemediate 
stateful things can get bored).  The setup/teardown do though :-) But 
they can be proxied. Our previous satellite modem proxied TCP locally 
and ran a more-suitable-satellite protocol from the modem to the 
downstation, where it became TCP again and went on its way.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Cameron Simpson
On 07Feb2022 11:40, Grant Edwards  wrote:
>Ah, c'mon... Every geek worth his salt knows a few real world IP
>addresses without relying on DNS. If you want to "ping Google", it's
> $ ping 8.8.8.8
> $ ping 8.8.4.4

And Cloudflare is 1.1.1.1. Speaking as someone who's seen his upstream 
provider have good G connectivity and degraded C connectiviy :-(

>If that doesn't work, then you ask 'route -n' for the IP address of
>the default gateway,

I tend to just check for the presence of the default route for services 
which should be "up" when there's internet. (Persistent ssh tunnels, in 
the main.) Not even a ping.

Some of those tunnels are further conditioned on a specific ping.

"ping -c 5 -q ip-addr-here" can be a simple Boolean test.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Grant Edwards
On 2022-02-07, Dennis Lee Bieber  wrote:
> On Mon, 07 Feb 2022 11:40:24 -0800 (PST), Grant Edwards
> declaimed the following:
>
>>On 2022-02-07, Dennis Lee Bieber  wrote:
>>
>>> Also, for a machine freshly booted, with no cache, even pinging
>>> Google first requires making contact with a DNS server to ask for
>>> Google's IP address. With no network, the DNS look-up will fail
>>> before ping even tries to hit Google.
>>
>>Ah, c'mon... Every geek worth his salt knows a few real world IP
>>addresses without relying on DNS. If you want to "ping Google", it's
>>
>> $ ping 8.8.8.8
>>or
>> $ ping 8.8.4.4
>>
>
> Which happen to be Google's DNS servers -- not what most think of as
> "Google"

Right. So even asking "do you have Google" is too vague. :)

> Manipulates network routing tables.

Sorry, I didn't know that the Windows "route" command didn't recognize the
standard -n option.

--
Grant

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Dennis Lee Bieber
On Mon, 07 Feb 2022 11:40:24 -0800 (PST), Grant Edwards
 declaimed the following:

>On 2022-02-07, Dennis Lee Bieber  wrote:
>
>> Also, for a machine freshly booted, with no cache, even pinging
>> Google first requires making contact with a DNS server to ask for
>> Google's IP address. With no network, the DNS look-up will fail
>> before ping even tries to hit Google.
>
>Ah, c'mon... Every geek worth his salt knows a few real world IP
>addresses without relying on DNS. If you want to "ping Google", it's
>
> $ ping 8.8.8.8
>or
> $ ping 8.8.4.4
>

Which happen to be Google's DNS servers -- not what most think of as
"Google"

C:\Users\Wulfraed>ping www.google.com -4

Pinging www.google.com [142.251.45.36] with 32 bytes of data:
...


>:)
>
>If that doesn't work, then you ask 'route -n' for the IP address of
>the default gateway, and try pinging that. It's possible your default
>gateway is alive but configured to ignore ICMP ping requests, but I've
>never run into one like that.
>

No "route -n" here...

C:\Users\Wulfraed>route -n

Manipulates network routing tables.

ROUTE [-f] [-p] [-4|-6] command [destination]
  [MASK netmask]  [gateway] [METRIC metric]  [IF interface]

  -f   Clears the routing tables of all gateway entries.  If this
is
   used in conjunction with one of the commands, the tables are
   cleared prior to running the command.

  -p   When used with the ADD command, makes a route persistent
across
   boots of the system. By default, routes are not preserved
   when the system is restarted. Ignored for all other
commands,
   which always affect the appropriate persistent routes.

  -4   Force using IPv4.

  -6   Force using IPv6.

  command  One of these:
 PRINT Prints  a route
 ADD   Addsa route
 DELETEDeletes a route
 CHANGEModifies an existing route
  destination  Specifies the host.
  MASK Specifies that the next parameter is the 'netmask' value.
  netmask  Specifies a subnet mask value for this route entry.
   If not specified, it defaults to 255.255.255.255.
  gateway  Specifies gateway.
  interfacethe interface number for the specified route.
  METRIC   specifies the metric, ie. cost for the destination.
...


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Chris Angelico
On Tue, 8 Feb 2022 at 06:41, Grant Edwards  wrote:
> But, as has been pointed out previously "if there is internet" is too
> vague a question to have an answer.
>
> If all you have is proxied access to outside HTTPS servers, then I
> would consider the answer to be "no", but most people would say "yes"
> they have internet.

Some day, we'll have people on Mars. They won't have TCP connections -
at least, not unless servers start supporting connection timeouts
measured in minutes or hours - but it wouldn't surprise me if some
sort of caching proxy system is deployed.

On the other hand, it also wouldn't surprise me if we do everything at
a high level instead - have a Martian PyPI mirror, Debian package
mirror, etc, etc, etc - and then build a mirror synchronization
protocol that uses UDP.

Either way, though: would a person on Mars "have the internet"? Yes,
but not the internet as we know it...

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Grant Edwards
On 2022-02-07, Dennis Lee Bieber  wrote:

> Also, for a machine freshly booted, with no cache, even pinging
> Google first requires making contact with a DNS server to ask for
> Google's IP address. With no network, the DNS look-up will fail
> before ping even tries to hit Google.

Ah, c'mon... Every geek worth his salt knows a few real world IP
addresses without relying on DNS. If you want to "ping Google", it's

 $ ping 8.8.8.8
or
 $ ping 8.8.4.4

:)

If that doesn't work, then you ask 'route -n' for the IP address of
the default gateway, and try pinging that. It's possible your default
gateway is alive but configured to ignore ICMP ping requests, but I've
never run into one like that.

But, as has been pointed out previously "if there is internet" is too
vague a question to have an answer.

If all you have is proxied access to outside HTTPS servers, then I
would consider the answer to be "no", but most people would say "yes"
they have internet.

If all you have is NAT'ed outbound TCP connections, even more people
would say "yes they have internet", but I would still answer "partially".

--
Grant
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Dennis Lee Bieber
On Mon, 7 Feb 2022 13:33:54 +0400, Abdur-Rahmaan Janhangeer
 declaimed the following:

>Popular browsers tell: No internet connection detected. A function that
>goes in the same sense. Unless they too are pinging Google.com to check ...
>

Ah, but WHEN do those browsers report that? When attempting to connect
to whatever the default "home" page has been set to? (Mine is configured to
use https://www.google.com as the default page -- if my router is down,
obviously the browser will time-out waiting for a response from Google, and
report "no network").

Pretty much any discovery of "no network" occurs when the application
attempts to make a normal connection to some target -- using whatever
protocol is normal for that application -- and fails to get a response.
ping is not a solution -- it is possible for firewalls to be configured to
drop with no response specific packets. A firewall configured to DROP
rather than REJECT results in a machine that just "isn't there" to outside
poking. That doesn't mean that the network is down -- only that the machine
you tried to poke is ignoring you.

Also, for a machine freshly booted, with no cache, even pinging Google
first requires making contact with a DNS server to ask for Google's IP
address. With no network, the DNS look-up will fail before ping even tries
to hit Google.

Consider that UDP is often used in a "fire and forget" mode -- packets
get sent to the network interface for forwarding, but there is no
expectation that the transport system will return success/failure packets.
For UDP, any such has to be built into the application level protocol(s).
TCP, OTOH, /is/ a "connected" protocol expecting to receive ACK/NAK packets
for each one it sends out. If it doesn't receive either it will, after some
time-out period, declare a broken connection.


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Chris Angelico
On Mon, 7 Feb 2022 at 23:48, Lars Liedtke  wrote:
>
> Each Browser is doing it differently and even Windows or
> Linux-Desktopmanagers (NetworkManager).
>
> I have had cases, where one tool told me I had Internet and another one
> I hadn't.

Not at all surprised :) Though that situation would probably be best
described as "degraded service". (Unless one tool was straight-up
misconfigured, of course.)

> So What Chris Angelico wrote is propably the best way, ping e.g. Google,
> do a DNS lookup and try http for Status 200. Each with its own
> Errorhandling and if you have got all three, then it is propable that
> you have "Internet".
>

More specifically, what I'm saying is that the best way to determine
whether you "have internet" is to do the exact thing that you care
about. What do you need the internet for? Downloading things from web
sites? Then attempt an HTTP request. Do you need UDP transmission?
Then send a UDP packet somewhere and wait for a response. Etc.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Lars Liedtke
P.S.: for ping a startingpoint can be icmplib, for dns dnspython and for 
http requests. But consider as well if you want to check for IPv4 and/or 
IPv6 Connectivity.


Am 07.02.22 um 13:47 schrieb Lars Liedtke:
Each Browser is doing it differently and even Windows or 
Linux-Desktopmanagers (NetworkManager).


I have had cases, where one tool told me I had Internet and another 
one I hadn't.


So What Chris Angelico wrote is propably the best way, ping e.g. 
Google, do a DNS lookup and try http for Status 200. Each with its own 
Errorhandling and if you have got all three, then it is propable that 
you have "Internet".


Cheers

Lars

Am 07.02.22 um 10:33 schrieb Abdur-Rahmaan Janhangeer:

Popular browsers tell: No internet connection detected. A function that
goes in the same sense. Unless they too are pinging Google.com to 
check ...


Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius


On Mon, Feb 7, 2022 at 1:28 PM Chris Angelico  wrote:


On Mon, 7 Feb 2022 at 20:18, Abdur-Rahmaan Janhangeer
 wrote:

Greetings,

Using the standard library or 3rd party libraries, what's the
best way to check if there is internet? Checking if google.com
is reachable is good but I wonder if there is a more native,
protocol-oriented
way of knowing?


What do you mean by "if there is internet"? How low a level of
connection do you want to test? You could ping an IP address that you
know and can guarantee will respond. You could attempt a DNS lookup.
You could try an HTTP request. Each one can fail in different ways,
for different reasons. It's best to test what you actually care about.

Even this URL recommends checking if a domain is up as a way to 
check for

internet connectivity:

https://www.ibm.com/support/pages/checking-network-connectivity-when-using-python-and-ibm-resilient-circuits 



That talks about a misconfigured proxy as being the most likely cause.
Is that something you're trying to test for?

There is no single concept of "there is internet". (Other than, in a
trivial sense, that the internet does exist.) What you need to know is
"can I use the internet?", and ultimately, that depends on what you
need it to do.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list


--
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Lars Liedtke
Each Browser is doing it differently and even Windows or 
Linux-Desktopmanagers (NetworkManager).


I have had cases, where one tool told me I had Internet and another one 
I hadn't.


So What Chris Angelico wrote is propably the best way, ping e.g. Google, 
do a DNS lookup and try http for Status 200. Each with its own 
Errorhandling and if you have got all three, then it is propable that 
you have "Internet".


Cheers

Lars

Am 07.02.22 um 10:33 schrieb Abdur-Rahmaan Janhangeer:

Popular browsers tell: No internet connection detected. A function that
goes in the same sense. Unless they too are pinging Google.com to check ...

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius


On Mon, Feb 7, 2022 at 1:28 PM Chris Angelico  wrote:


On Mon, 7 Feb 2022 at 20:18, Abdur-Rahmaan Janhangeer
 wrote:

Greetings,

Using the standard library or 3rd party libraries, what's the
best way to check if there is internet? Checking if google.com
is reachable is good but I wonder if there is a more native,
protocol-oriented
way of knowing?


What do you mean by "if there is internet"? How low a level of
connection do you want to test? You could ping an IP address that you
know and can guarantee will respond. You could attempt a DNS lookup.
You could try an HTTP request. Each one can fail in different ways,
for different reasons. It's best to test what you actually care about.


Even this URL recommends checking if a domain is up as a way to check for
internet connectivity:


https://www.ibm.com/support/pages/checking-network-connectivity-when-using-python-and-ibm-resilient-circuits

That talks about a misconfigured proxy as being the most likely cause.
Is that something you're trying to test for?

There is no single concept of "there is internet". (Other than, in a
trivial sense, that the internet does exist.) What you need to know is
"can I use the internet?", and ultimately, that depends on what you
need it to do.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list


--
punkt.de GmbH
Lars Liedtke
.infrastructure

Kaiserallee 13a 
76133 Karlsruhe

Tel. +49 721 9109 500
https://infrastructure.punkt.de
i...@punkt.de

AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein

--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Abdur-Rahmaan Janhangeer
Popular browsers tell: No internet connection detected. A function that
goes in the same sense. Unless they too are pinging Google.com to check ...

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius


On Mon, Feb 7, 2022 at 1:28 PM Chris Angelico  wrote:

> On Mon, 7 Feb 2022 at 20:18, Abdur-Rahmaan Janhangeer
>  wrote:
> >
> > Greetings,
> >
> > Using the standard library or 3rd party libraries, what's the
> > best way to check if there is internet? Checking if google.com
> > is reachable is good but I wonder if there is a more native,
> > protocol-oriented
> > way of knowing?
> >
>
> What do you mean by "if there is internet"? How low a level of
> connection do you want to test? You could ping an IP address that you
> know and can guarantee will respond. You could attempt a DNS lookup.
> You could try an HTTP request. Each one can fail in different ways,
> for different reasons. It's best to test what you actually care about.
>
> > Even this URL recommends checking if a domain is up as a way to check for
> > internet connectivity:
> >
> https://www.ibm.com/support/pages/checking-network-connectivity-when-using-python-and-ibm-resilient-circuits
>
> That talks about a misconfigured proxy as being the most likely cause.
> Is that something you're trying to test for?
>
> There is no single concept of "there is internet". (Other than, in a
> trivial sense, that the internet does exist.) What you need to know is
> "can I use the internet?", and ultimately, that depends on what you
> need it to do.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if there is internet?

2022-02-07 Thread Chris Angelico
On Mon, 7 Feb 2022 at 20:18, Abdur-Rahmaan Janhangeer
 wrote:
>
> Greetings,
>
> Using the standard library or 3rd party libraries, what's the
> best way to check if there is internet? Checking if google.com
> is reachable is good but I wonder if there is a more native,
> protocol-oriented
> way of knowing?
>

What do you mean by "if there is internet"? How low a level of
connection do you want to test? You could ping an IP address that you
know and can guarantee will respond. You could attempt a DNS lookup.
You could try an HTTP request. Each one can fail in different ways,
for different reasons. It's best to test what you actually care about.

> Even this URL recommends checking if a domain is up as a way to check for
> internet connectivity:
> https://www.ibm.com/support/pages/checking-network-connectivity-when-using-python-and-ibm-resilient-circuits

That talks about a misconfigured proxy as being the most likely cause.
Is that something you're trying to test for?

There is no single concept of "there is internet". (Other than, in a
trivial sense, that the internet does exist.) What you need to know is
"can I use the internet?", and ultimately, that depends on what you
need it to do.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list