Skip to content

Commit

Permalink
Merge pull request #4 from nhymxu/dev
Browse files Browse the repository at this point in the history
update README. Simple usage guide
  • Loading branch information
nhymxu authored Nov 11, 2019
2 parents 858c916 + e019c49 commit 7048fb3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,76 @@
# cf-dns-update-python
Dynamic DNS record update utility for CloudFlare DNS service. Python implement

### Requirements

- Linux/macOS (tested with macOS 10.15.1 & Ubuntu 18.04)
- Python 3 ( version >= 3.6 is recommended )

### Download & Setup

#### Download
Download code from Release page.

Link here: [https://github.com/nhymxu/cf-dns-update-python/releases/latest](https://github.com/nhymxu/cf-dns-update-python/releases/latest)

Or

clone repo using git:

```shell
git clone [email protected]:nhymxu/cf-dns-update-python.git
```

#### Create CloudFlare Token

1. Go to CloudFlare dash
2. Click open any domain you have
3. Scroll to bottom, you can see **API** section from right column.
4. Click `Get your API token`
5. Click `Create Token`
6. Enter Token name
7. On `Permissions` section. Choose `Zone` - `DNS` - `Edit`
8. On `Zone resource` section. Choose `Include` - `All zone` or specific zone you want.
9. Click `Continue to Summary`
10. Copy token display on page

#### Setup CloudFlare Token

Copy file `config.ini.sample` to current folder with name `config.ini`

Add CloudFlare token to first section like this

```ini
[common]
CF_API_TOKEN = token_key_here
```

#### Setup record to update

1. Look at step **3** on section `Create CloudFlare Token`
2. Copy `Zone ID`
3. Add to `config.ini` like this:

```ini
[dungnt.net]
zone_id = zone_id_here
record = test.dungnt.net
```

### Auto running

I want my script auto running every `x` minutes. So I need set up cronjob for it.

From server shell, typing:

```shell
crontab -e
```

And add this line to end of file

```text
*/15 * * * * /opt/cf-dns-update-python/run.sh
```

This script will run each 15 minutes.
15 changes: 15 additions & 0 deletions cf-dns-update.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# -*- coding: utf-8 -*-

"""
Dynamic DNS record update utility for CloudFlare DNS service.
(c) Dung Nguyen (nhymxu)
"""

import configparser
import json
import urllib.error
Expand Down Expand Up @@ -36,6 +43,14 @@ def get_local_ip():
Get current public IP of server
:return: string
"""

'''
Other domain can using to get IP:
ifconfig.me
icanhazip.com
ipecho.net/plain
ifconfig.co
'''
endpoint = "https://checkip.amazonaws.com/"

return make_request(url=endpoint).strip().decode('utf-8')
Expand Down

0 comments on commit 7048fb3

Please sign in to comment.