Find Your External IP Address
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
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
$
Mastodon Automated Postings using the API
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:
- Sign into your Mastodon account
- Click on In the
"Preferences"
link. - On the bottom left corner of that page, click the
"Development"
link. - On the
"Your Applications"
page, click the blueNEW APPLICATION
button. - 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 (i
read
,write
, andfollow
are the defaults). You can always change this later. - At the bottom of the page, click the blue
SUBMIT
button. - You will be directed back to the
Your applications
page, but now you should see your application name. Click that. - 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'