Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

Find Your External IP Address

September 13, 2023 — Gregg Szumowski

It’s easy to find your internal IP address my using tools like ifconfig or ip a but to find your external IP address (the one that connects you to the outside world) you must use other means. Here are 3 simple commands that you can use to do just that:

$ curl ifcfg.me
72.76.yyy.xxx

$ curl icanhazip.com
72.76.yyy.xxx

$ nslookup myip.opendns.com. resolver1.opendns.com
Server: resolver1.opendns.com
Address: 208.67.222.222#53

Non-authoritative answer:
Name: myip.opendns.com
Address: 72.76.yyy.xxx

Tags: cli, network, curl, nslookup, motd

Sending Email from the Command Line with cURL

June 06, 2023 — Gregg Szumowski

Let’s assume that you had a RFC 5822 formatted file named mail.txt as follows:

From: Some Sender <some.sender@gmail.com>
To: Some Recipient <some.recipient@example.com>
Subject: Saying Hello
Date: Tue, 6 Jun 2023 04:15:06 -0100
Message-ID: <1234@local.machine.example>

This is a message just to say hello.
So, "Hello".

You can forward this to a email recipient using Google’s SMTP with the following curl command provided you have a Google app password:

$ curl --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
 --mail-from 'some.sender@gmail.com' \ 
 --mail-rcpt 'some.recipient@example.com' \
 --upload-file mail.txt \
 --user 'some.sender@gmail.com:your-gmail-app-password'

Output should be something like this:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    12    0     0  100    12      0     10  0:00:01  0:00:01 --:--:--    10
$

Tags: cli, curl, mail, motd

Mastodon Automated Postings using the API

May 16, 2023 — Gregg Szumowski

You can post to Mastodon using their API using cURL.

Create or Find Your Access Token

Once you have a Mastodon account, you need your account's access token. The steps you need to get that:

  1. Sign into your Mastodon account
  2. Click on In the "Preferences" link.
  3. On the bottom left corner of that page, click the "Development" link.
  4. On the "Your Applications" page, click the blue NEW APPLICATION button.
  5. Give your application a name, and decide what kind of access you want to have when you connect to your account via the Mastodon API (iread, write, and follow are the defaults). You can always change this later.
  6. At the bottom of the page, click the blue SUBMIT button.
  7. You will be directed back to the Your applications page, but now you should see your application name. Click that.
  8. In your application's page, there are three tokens. For this tutorial, you need the Your access token one. Note: if your access token is ever compromised, you can click regenerate, and your old access token will stop working, and you'll be shown a new one.

Post a Status Update using cURL


$ curl https://mastodon.sdf.org/api/v1/statuses -H 'Authorization: Bearer put-your-api-token-here' -F 'status=Hello, World'

Tags: curl, mastodon, api, motd