mirror of
https://github.com/jakejarvis/simpip.git
synced 2025-06-27 16:15:41 -04:00
Finally publishing the Cloudflare Worker version!
This commit is contained in:
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Jake Jarvis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
46
README.md
46
README.md
@ -1,3 +1,43 @@
|
||||
simpip.com
|
||||
=========
|
||||
A very simple IP utility that shows the user's IP address–and only the user's IP address–on a plaintext page using PHP.
|
||||
# 🌎 [simpip.com](https://simpip.com/)
|
||||
|
||||
**⚡ Now powered purely by [Cloudflare Workers](https://www.cloudflare.com/products/cloudflare-workers/) — [try this code on the playground!](https://cloudflareworkers.com/#12bf2207fc352f52ebb27a041753c03d:https://tutorial.cloudflareworkers.com/)** The ancient PHP version is [archived here](https://github.com/jakejarvis/simpip/tree/php).
|
||||
|
||||
A very, *very* "simple" web server that returns the visitor's IP address in plaintext...and **literally nothing** else. Perfect for CLI usage via `curl` or for automated tasks.
|
||||
|
||||
This returns your IPv6 address by default, but to choose one or the other you can use [`curl`](https://curl.haxx.se/docs/manpage.html) flags:
|
||||
|
||||
```bash
|
||||
curl simpip.com # returns IPv6 *OR* IPv4
|
||||
curl -4 simpip.com # returns IPv4
|
||||
curl -6 simpip.com # returns IPv6, or fails to connect if network is incompatible
|
||||
```
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
In [my terminal's dotfiles](https://github.com/jakejarvis/dotfiles), I have three aliases:`ip4` and `ip6` which are self-explanatory, and simply `ip` which returns **both** addresses *iff* your network supports IPv6 — otherwise, IPv6 sliently fails and only your IPv4 address is shown.
|
||||
|
||||
```bash
|
||||
alias ip4="curl -4 simpip.com --max-time 1 --proto-default https --silent"
|
||||
alias ip6="curl -6 simpip.com --max-time 1 --proto-default https --silent"
|
||||
alias ip="ip6; ip4"
|
||||
```
|
||||
|
||||
Timeout is set to 1 second via `--max-time 1` (otherwise we will get stuck indefinitely trying to connect via IPv6 even if our network doesn't support it) and a secure connection preference is set using `--proto-default https`. Connection errors (particularly for IPv6) are silenced using `--silent`, so that the output of `ip` contains nothing but IP addresses, like so:
|
||||
|
||||
```bash
|
||||
jake@macbook:~$ ip4
|
||||
1.1.1.1
|
||||
|
||||
jake@macbook:~$ ip6
|
||||
2606:4700:4700::1111
|
||||
|
||||
jake@macbook:~$ ip
|
||||
2606:4700:4700::1111
|
||||
1.1.1.1
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
This project is distributed under the [MIT license](LICENSE.md).
|
||||
|
22
index.js
Normal file
22
index.js
Normal file
@ -0,0 +1,22 @@
|
||||
addEventListener('fetch', event => {
|
||||
event.respondWith(handle(event.request))
|
||||
})
|
||||
|
||||
async function handle(request) {
|
||||
return new Response(request.headers.get("cf-connecting-ip") + "\n", {
|
||||
status: 200,
|
||||
statusText: "OK",
|
||||
headers: {
|
||||
"Content-Type": "text/plain",
|
||||
"Content-Security-Policy": "default-src 'none';",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"X-XSS-Protection": "1; mode=block",
|
||||
"X-Frame-Options": "SAMEORIGIN",
|
||||
"Referrer-Policy": "no-referrer",
|
||||
"Cache-Control": "max-age=0, no-cache, no-store, must-revalidate",
|
||||
"Pragma": "no-cache",
|
||||
"Expires": "Wed, 11 Jan 1984 05:00:00 GMT",
|
||||
"X-Did-You-Know": "You can visit ipv4.simpip.com or ipv6.simpip.com to get either address!"
|
||||
}
|
||||
});
|
||||
}
|
12
index.php
12
index.php
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
header("Content-type: text/plain");
|
||||
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
if (($pos = strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ",")) !== false) {
|
||||
echo substr($_SERVER['HTTP_X_FORWARDED_FOR'], 0, $pos);
|
||||
} else {
|
||||
echo $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
}
|
||||
} else {
|
||||
echo $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user