snipt

Ctrl+h for KB shortcuts

Bash

validate IP

[[ "$IP" =~ ^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]] && echo "valid" || echo "invalid"
https://snipt.net/embed/a9253d8df5f51a88c9becb1b4c407589/
https://snipt.net/raw/a9253d8df5f51a88c9becb1b4c407589/
a9253d8df5f51a88c9becb1b4c407589
bash
Bash
1
2016-09-28T22:29:46
True
False
False
Oct 18, 2015 at 12:39 PM
/api/public/snipt/141789/
validate-ip
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="o">[[</span> <span class="s2">&quot;</span><span class="nv">$IP</span><span class="s2">&quot;</span> <span class="o">=</span>~ ^<span class="o">(([</span>0-9<span class="o">]</span><span class="p">|</span><span class="o">[</span>1-9<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>1<span class="o">[</span>0-9<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>2<span class="o">[</span>0-4<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>25<span class="o">[</span>0-5<span class="o">])</span>.<span class="o">){</span>3<span class="o">}([</span>0-9<span class="o">]</span><span class="p">|</span><span class="o">[</span>1-9<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>1<span class="o">[</span>0-9<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>2<span class="o">[</span>0-4<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>25<span class="o">[</span>0-5<span class="o">])</span><span class="nv">$ </span><span class="o">]]</span> <span class="o">&amp;&amp;</span> <span class="nb">echo</span> <span class="s2">&quot;valid&quot;</span> <span class="o">||</span> <span class="nb">echo</span> <span class="s2">&quot;invalid&quot;</span> </span></pre></div> </td></tr></table>
bash, ip, linux

Bash

Get External IP Address

#!/bin/bash
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//' 
https://snipt.net/embed/9f871bc6f2b9d0c3cd5a2567088aae5c/
https://snipt.net/raw/9f871bc6f2b9d0c3cd5a2567088aae5c/
9f871bc6f2b9d0c3cd5a2567088aae5c
bash
Bash
2
2016-09-28T15:59:16
True
False
False
Dec 09, 2013 at 04:42 PM
/api/public/snipt/99496/
get-external-ip-address
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c">#!/bin/bash</span> </span><span id="L-2"><a name="L-2"></a>wget -q -O - checkip.dyndns.org<span class="p">|</span>sed -e <span class="s1">&#39;s/.*Current IP Address: //&#39;</span> -e <span class="s1">&#39;s/&lt;.*$//&#39;</span> </span></pre></div> </td></tr></table>
address, ip

Text only

Deny access to folder for not specified ip address

1
2
3
4
ORDER DENY,ALLOW
  DENY FROM ALL
  ALLOW FROM 127.0.0.1
  ALLOW FROM 0.0.0.0
https://snipt.net/embed/cd530c72835dec31298f2182f27f92ea/
https://snipt.net/raw/cd530c72835dec31298f2182f27f92ea/
cd530c72835dec31298f2182f27f92ea
text
Text only
4
2016-09-28T18:33:52
True
False
False
/api/public/snipt/39473/
deny-access-to-folder-for-not-specified-ip-address
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>ORDER DENY,ALLOW </span><span id="L-2"><a name="L-2"></a> DENY FROM ALL </span><span id="L-3"><a name="L-3"></a> ALLOW FROM 127.0.0.1 </span><span id="L-4"><a name="L-4"></a> ALLOW FROM 0.0.0.0 </span></pre></div> </td></tr></table>
deny, folder, htaccess, ip

PHP

User IP Address

1
2
3
4
5
<?php

echo $_SERVER['REMOTE_ADDR'];

?>
https://snipt.net/embed/cf61c2cf192cca308af374dfea924c0e/
https://snipt.net/raw/cf61c2cf192cca308af374dfea924c0e/
cf61c2cf192cca308af374dfea924c0e
php
PHP
5
2016-09-25T07:52:00
True
False
False
/api/public/snipt/39058/
user-ip-address
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">echo</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;REMOTE_ADDR&#39;</span><span class="p">];</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
ip, php
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.