Wednesday, May 29, 2019

測試網路下載速度的小工具

在Ubuntu下若想要簡單測試目前Internet下載速度的話,可以用Netflix出的一個小軟體fast來測試。

安裝:
$ snap install fast

執行
$ fast















就是這麼簡單。

Monday, May 13, 2019

Canonical QA offsite meeting之Python 練習

5月初部門舉辦了一次offsite meeting,主題是學習Python。

內部同事兼講師,教材準備得很好,上課內容又豐富,所以當然要把回家作業完成。

Exercise 1

Write a function that takes a string and returns the inverted string (e.g. Taiwan → nawiaT). This function must use a for loop.

Exercise 2

Same as exercise 1, but using the easiest/shortest way (hint: the answer is somewhere in the previous sections.

Exercise 3

Dictionary containing all Ubuntu releases. The key is the release number (e.g. “18.04”) and the value is the release codename (e.g. “Bionic Beaver”):

  • Using Python code:return the release codenames for versions released in October
  • find how many releases were released neither in April nor October
  • return the version number for versions whose codename contains a “k”

Exercise 4

Write a function that reads the content of a text file and returns a dictionary with the number of occurrences for each letter of the alphabet

以下是我寫的code:

Exercise 1

def revert(word):
    for i in range(len(word)-1, -1, -1):
        print(word[i],end="")

revert("I love Taiwan")

Exercise 2

string="Taiwan"
print(string[::-1])

Exercise 3

Ubuntu={ "4.10": "Warty Warthog", "5.04": "Hoary Hedgehog", "5.10": "Breezy Badger", "6.06": "Dapper Drake", "6.10": "Edgy Eft", "7.04": "Feisty Fawn", "7.10": "Gutsy Gibbon", "8.04": "Hardy Heron", "8.10": "Intrepid Ibex", "9.04": "Jaunty Jackalope", "9.10": "Karmic Koala", "10.04": "Lucid Lynx", "10.10": "Maverick Meerkat", "11.04": "Natty Narwhal", "11.10": "Oneiric Ocelot", "12.04": "Precise Pangolin", "12.10": "Quantal Quetzal", "13.04": "Raring Ringtail", "13.10": "Saucy Salamander", "14.04": "Trusty Tahr", "14.10": "Utopic Unicorn", "15.04": "Vivid Vervet", "15.10": "Wily Werewolf", "16.04": "Xenial Xerus", "16.10": "Yakkety Yak", "17.04": "Zesty Zapus", "17.10": "Artful Aardvark", "18.04": "Bionic Beaver", "18.10": "Cosmic Cuttlefish", "19.04": "Disco Dingo" } for number in Ubuntu.keys(): if number.split(".")[1]=="10": print("OCT=",Ubuntu[number]) for number in Ubuntu.keys(): if number.split(".")[1]!="10" and number.split(".")[1]!="04": print("Neither in APR or OCT:",Ubuntu[number]) for codename in Ubuntu.values(): if "k" in codename.lower(): print("Codename contains a K or k:",codename)

Exercise 4

LIST=[]
for w in range(ord('a'), ord('z') + 1):
    LIST.append(chr(w))

ACCOUNT=[]
for i in range(0,26):
    ACCOUNT.append(0)

with open('/usr/share/doc/python3/copyright','r') as f:
    for alphabet in f.read():
        for i in range(0,26):
            if alphabet.lower()==LIST[i]:
                ACCOUNT[i]=ACCOUNT[i]+1
                break


dictionary=dict(zip(LIST,ACCOUNT))
print(dictionary)

老實說我有一段時間沒寫程式了,但稍微學習了一下Python後,它的語法很簡潔好懂,果然是受歡迎的程式語言之一呀!

Wednesday, May 08, 2019

在Ubuntu 18.04 Server 快速架設FreeRADIUS Server

比起以前在Linux架設FreeRADIUS server的難度與花費的時間,目前在Ubuntu安裝並配置FreeRADIUS server真的是輕鬆了許多。廢話不多說,以下筆記如何在Ubuntu Server 18.04安裝並且配置一台可以使用的FreeRADIUS server。

環境:
Ubuntu Server 18.04.02 LTS















安裝:
# apt install freeradius















配置:
1. 建立使用者帳號:
先切換到FreeRADIUS server的目錄,然後開啟檔案users
# cd /etc/freeradius/3.0
# vi users
















這裡我將套用一個內建的帳號bob:















修改clients.conf: (這個檔案主要是限制哪些client可以使用FreeRADIUS server)
# vi clients.conf
















以上我新增了於subnet 10.101.47.0/24的client都可以使用FreeRADIUS server,並且secret是testing123

重新啟動FreeRADIUS server:
# systemctl restart freeradius
# systemctl status freeradius



















從遠端機器驗證:
$ radtest bob hello 10.101.47.37 1812 testing123

bob -> 帳號
hello -> 密碼
10.101.47.37 -> FreeRADIUS server's IP
1812 -> FreeRADIUS server's port (認証用)
testing123 -> FreeRADIUS server's secret



















一個FreeRADIUS server到這邊已經可以正常運行在Ubuntu Server 18.04,有空在跟大家介紹如何讓FreeRADIUS支援802.1X或是結合mysql儲存使用者的帳號密碼。