Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
134 views
in Technique[技术] by (71.8m points)

html - How To Create WIFI splash page Using Python

It Is Possible To Create Wifi Splash Page Using Python ???
When Someone Connect My WIFI Automatically Load My HTML Page
AnyOne Have An Idea Please Answer

question from:https://stackoverflow.com/questions/66058349/how-to-create-wifi-splash-page-using-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In linux you need install Nmap ("Network Mapper"):

sudo apt install nmap

and

pip3 install who-is-on-my-wifi

This code scans and write html than open it, you can make it with if conditions and while:

import who_is_on_my_wifi
import subprocess, sys

WHO = who_is_on_my_wifi.who()
body = ''

for i in range(0, len(WHO)):
    body += '<p>' + ' '.join(WHO[i]) + '</p>
' 

page = f'''<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
  {body}
</body>
</html>'''

with open("connections.html", "w") as write_file:
   write_file.write(page)

# opener ="open" if sys.platform == "darwin" else "xdg-open"    
# break with sudo:     subprocess.call([opener, 'connections.html'])

subprocess.call(['sudo', '-u', 'daniil', 'xdg-open', 'wifi.html'])

When you run without sudo it shows only your IP :(

sudo python3 wifi.py

on browser you can see:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...