B
B
B1ackGh0st2015-04-02 09:43:25
linux
B1ackGh0st, 2015-04-02 09:43:25

How to check if a network interface has received an IP address and Internet access in Python?

Hello.
Is it possible to check if an IP address has been received and if there is Internet access in python
I am trying to write a program to change ip and mac addresses when the Internet connection is lost

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Disen, 2015-04-02
@Disen

The simplest thing is to ping some resource on the Internet.

import os
hostname = "8.8.8.8" 
response = os.system("ping -c 1 " + hostname)
if response == 1:
  print('is up!')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question