Generate an SSID and password, make it a QR code and throw it into Slack.

I want to automate the task of updating the SSID and password of the guest wireless LAN

Updating the guest wifi settings is a hassle, so I'm going to automate this task.

What you can do

--When you run the script, Slack will be issued a QR code with wireless LAN configuration information. --Reading the QR code issued to slack with an iPhone or Android device suggests a wireless LAN connection.

In terms of images, let's do this. 写真 2020-01-01 17 49 24.png

Outline of the mechanism

  1. Generate SSID and password
  2. Make the generated information a QR code image
  3. Make an image of SSID and password information
  4. Throw the above content into Slack

environment

Implementation

See the code I wrote on Github

Try using

Slack settings (OK if you can get Token)

  1. Select app in slack and add bot スクリーンショット 2020-01-01 13.56.34.png スクリーンショット 2020-01-01 13.56.57.png

  2. Give the bot a name スクリーンショット 2020-01-01 13.58.41.png

  3. Get a Token for the bot (this token will be set later) スクリーンショット 2020-01-01 13.58.58.png

Set in python code

rice_cooker.py(8th to 13th lines)


# Please Write Your Wi-Fi Setting & Slack Token & Font Path
CONPANY_NAME        = 'GUEST'
ENCRYPTION_METHOD   = 'WPA'
SLACK_TOKEN         = ''
SLACK_CHANNEL       = 'freewifi-dev'
FONT_PATH           = '/usr/share/fonts/dejavu/DejaVuSans.ttf'

Enter the following items.

Drop and confirm QR code on Slack

  1. Run with python3 rice_cooker.py スクリーンショット 2020-01-01 15.21.59.png

  2. Check the QR code, SSID and password on slack スクリーンショット 2020-01-01 15.22.15.png

Wi-Fi connection from iOS

  1. Start up your iPhone and read the QR code 写真 2020-01-01 17 44 50.png

  2. You will be prompted to connect to the network, so tap Connect 写真 2020-01-01 17 49 24.png

  3. Make sure you are connected to a wireless LAN 写真 2020-01-01 16 08 08.png

You have been successfully connected!

About network setting automation

Originally, after this process, there was code to connect to the AP with SSH and add and remove wireless LAN settings (SSID, Password). I thought I would implement it with Ansible or Netmiko, but the wireless LAN terminal I was using was an Aruba product, and I couldn't use them, so I supported it with Python's expect. If motivation remains, I will write about network setting automation with expect.

Addictive points

--Pillow's Image.width may not be processed correctly, so I replaced the processing with Image.size [0] and made the tea muddy.

reference

--Reference for password creation -Generate password for text with python --Issuance of QR code -Generate and save QR code image with Python, Pillow, qrcode --Image generation and combination -Add margins to the top, bottom, left and right of the image with Python, Pillow and resize -Paste another image to an image with Python, Pillow -Edit images and insert text in Python -How to use Python's image processing library Pillow (PIL) --Notification function to slack -How to upload images to Slack with Python - Docs » Reference » Image Module - slack - api chat.postMessage - slack - api files.upload

Recommended Posts

Generate an SSID and password, make it a QR code and throw it into Slack.
A python program that resizes a video and turns it into an image
How to generate a QR code and barcode in Python and read it normally or in real time with OpenCV
You can do it in 3 minutes! How to make a moving QR code (GIF)!
Let's make a Makefile and build it (super beginner)
I'll make a password!
Get an image from a web page and resize it
Associate Python Enum with a function and make it Callable
Make a given number of seconds into hours, minutes and seconds