.
ip
[BASH] Script BAN iptables -ipset V.2
#!/bin/bash
# Script name : Ban/Unban IP with Iptables
# iptables -I INPUT 1 -m set --match-set portsentry src -j DROP
ipsetmyips="/var/log/ipset_Myips_ip.txt"
ipsetips="/var/log/ipset_all_ip.txt"
badips="/var/log/banip.log"
mybadips="/var/log/banip_perso.log"
ipsetlm=`ipset list Myips | grep "$ZTARGET"`
mylistip=`grep "$ZTARGET" $mybadips`
### color
NC=$(tput sgr0)
NOC=$(tput sgr0)
reset=$(tput sgr0)
GREEN=$(tput setaf 2)
PINK=$(tput setaf 5)
BLUE=$(tput setaf 6)
RED=$(tput setaf 1)
YELLOW=$(tput setaf 3)
ORANGE=$(tput setaf 166)
#GRIS="\e[38;5;8m"
GRIS=$(tput setaf 246)
CNoir=$(tput setaf 0)
CRouge=$(tput setaf 1)
CVert=$(tput setaf 2)
Jaune=$(tput setaf 3)
CBeu=$(tput setaf 4)
CRose=$(tput setaf 5)
CCyan=$(tput setaf 6)
CBlanc=$(tput setaf 7)
CGris=$(tput setaf 8)
CFade=$(tput setaf 75)
CGris1=$(tput setaf 235)
On_Red=$(tput setab 124)
On_Green=$(tput setab 28) # ou 40
CALERT="$(tput setaf 0)$(tput setab 124)" # Bold White on red background
CAlert="${CBlanc}${On_Red}"
Cokvb="${CBlanc}${On_Green}"
Cokv="${CNoir}${On_Green}"
Cokvo="${CBlanc}${On_Green} OK $(tput sgr0)"
Cko="$(tput setaf 1)X$(tput sgr0)"
Cok="$(tput setaf 2)✔$(tput sgr0)"
txtred=$(tput setaf 1)
txtyel=$(tput setaf 3)
txtcya=$(tput setaf 6)
txtrst=$(tput sgr0)
ipset_Myips_check(){
IPSET_LIST_NAME="Myips"
# create the ipset if needed (or abort if does not exists and FORCE=no)
if ! ipset list -n|command grep -q "$IPSET_LIST_NAME"; then
if [[ ${FORCE:-no} != yes ]]; then
echo >&2 "Error: ipset does not exist yet, add it using:"
echo >&2 "# ipset create $IPSET_LIST_NAME -exist hash:net family inet hashsize ${HASHSIZE:-16384} maxelem ${MAXELEM:-65536}"
# exit 1
fi
# if ! ipset create "$IPSET_LIST_NAME" -exist hash:net family inet hashsize "${HASHSIZE:-16384}" maxelem "${MAXELEM:-65536}"; then
# echo >&2 "Error: while creating the initial ipset"
# exit 1
# fi
fi
# create the iptables binding if needed (or abort if does not exists and FORCE=no)
if ! iptables -nvL INPUT|command grep -q "match-set $IPSET_LIST_NAME"; then
# we may also have assumed that INPUT rule n°1 is about packets statistics (traffic monitoring)
if [[ ${FORCE:-no} != yes ]]; then
echo >&2 "Error: iptables does not have the needed ipset INPUT rule, add it using:"
echo >&2 "# iptables -I INPUT ${IPTABLES_IPSET_RULE_NUMBER:-1} -m set --match-set $IPSET_LIST_NAME src -j DROP"
# exit 1
fi
# if ! iptables -I INPUT "${IPTABLES_IPSET_RULE_NUMBER:-1}" -m set --match-set "$IPSET_LIST_NAME" src -j DROP; then
# echo >&2 "Error: while adding the --match-set ipset rule to iptables"
# exit 1
# fi
fi
echo -e "$Cok ipset ${CGris} $IPSET_LIST_NAME $(tput sgr0) checked"
unset IPSET_LIST_NAME
#echo "test IPSET_LIST_NAME $IPSET_LIST_NAME"
}
ipset_blockip_check(){
IPSET_LIST_NAME="blockip"
# create the ipset if needed (or abort if does not exists and FORCE=no)
if ! ipset list -n|command grep -q "$IPSET_LIST_NAME"; then
if [[ ${FORCE:-no} != yes ]]; then
echo >&2 "Error: ipset does not exist yet, add it using:"
echo >&2 "# ipset create $IPSET_LIST_NAME -exist hash:net family inet hashsize ${HASHSIZE:-16384} maxelem ${MAXELEM:-65536}"
# exit 1
fi
# if ! ipset create "$IPSET_LIST_NAME" -exist hash:net family inet hashsize "${HASHSIZE:-16384}" maxelem "${MAXELEM:-65536}"; then
# echo >&2 "Error: while creating the initial ipset"
# exit 1
# fi
fi
# create the iptables binding if needed (or abort if does not exists and FORCE=no)
if ! iptables -nvL INPUT|command grep -q "match-set $IPSET_LIST_NAME"; then
# we may also have assumed that INPUT rule n°1 is about packets statistics (traffic monitoring)
if [[ ${FORCE:-no} != yes ]]; then
echo >&2 "Error: iptables does not have the needed ipset INPUT rule, I will add it:"
echo >&2 " iptables -I INPUT ${IPTABLES_IPSET_RULE_NUMBER:-1} -m set --match-set $IPSET_LIST_NAME src -j DROP"
iptables -I INPUT ${IPTABLES_IPSET_RULE_NUMBER:-1} -m set --match-set $IPSET_LIST_NAME src -j DROP
# exit 1
fi
# if ! iptables -I INPUT "${IPTABLES_IPSET_RULE_NUMBER:-1}" -m set --match-set "$IPSET_LIST_NAME" src -j DROP; then
# echo >&2 "Error: while adding the --match-set ipset rule to iptables"
# exit 1
# fi
fi
echo -e "$Cok ipset ${CGris} $IPSET_LIST_NAME $(tput sgr0) checked"
unset IPSET_LIST_NAME
#echo "test $IPSET_LIST_NAME"
}
ipset_portsentry_check(){
IPSET_LIST_NAME="portsentry"
# create the ipset if needed (or abort if does not exists and FORCE=no)
if ! ipset list -n|command grep -q "$IPSET_LIST_NAME"; then
if [[ ${FORCE:-no} != yes ]]; then
echo >&2 "Error: ipset does not exist yet, add it using:"
echo >&2 "# ipset create $IPSET_LIST_NAME -exist hash:net family inet hashsize ${HASHSIZE:-16384} maxelem ${MAXELEM:-65536}"
# exit 1
fi
# if ! ipset create "$IPSET_LIST_NAME" -exist hash:net family inet hashsize "${HASHSIZE:-16384}" maxelem "${MAXELEM:-65536}"; then
# echo >&2 "Error: while creating the initial ipset"
# exit 1
# fi
fi
# create the iptables binding if needed (or abort if does not exists and FORCE=no)
if ! iptables -nvL INPUT|command grep -q "match-set $IPSET_LIST_NAME"; then
# we may also have assumed that INPUT rule n°1 is about packets statistics (traffic monitoring)
if [[ ${FORCE:-no} != yes ]]; then
echo >&2 "Error: iptables does not have the needed ipset INPUT rule, add it using:"
echo >&2 "# iptables -I INPUT ${IPTABLES_IPSET_RULE_NUMBER:-1} -m set --match-set $IPSET_LIST_NAME src -j DROP"
# exit 1
fi
# if ! iptables -I INPUT "${IPTABLES_IPSET_RULE_NUMBER:-1}" -m set --match-set "$IPSET_LIST_NAME" src -j DROP; then
# echo >&2 "Error: while adding the --match-set ipset rule to iptables"
# exit 1
# fi
fi
echo -e "$Cok ipset ${CGris} $IPSET_LIST_NAME $(tput sgr0) checked"
unset IPSET_LIST_NAME
#echo "test IPSET_LIST_NAME $IPSET_LIST_NAME"
}
ipset_check_(){
ipset_Myips_check
ipset_blockip_check
#ipset_portsentry_check
}
save_myips() {
# iptables -I INPUT -m set --match-set Myips src -j DROP
# [ -s `iptables -nL | grep "match-set Myips"` ] iptables -I INPUT -m set --match-set Myips src -j DROP || echo "Check iptables:"; iptables -nL | grep "match-set Myips"
echo -e "iptables rules for Myips: $Cok"
ipset save Myips | tail -n +2 > $ipsetmyips
echo -e " ipset save Myips > $ipsetmyips\n"
ipset save | tail -n +2 > $ipsetips
echo -e " ipset save > $ipsetips\n"
# Backup HOME / ipset perso
# /sbin/ipset -exist create Myips hash:ip hashsize 4096
/sbin/ipset save > /home/backup/ipset_save_all_$HOSTNAME_$(date "+%d.%m.%Y").txt
/sbin/ipset save Myips > /home/backup/ipset_Myips_save_$HOSTNAME_$(date "+%d.%m.%Y").txt
/sbin/ipset -exist create portsentry hash:ip hashsize 4096
/sbin/ipset save portsentry > /home/backup/ipset_portsentry_save_$HOSTNAME_$(date "+%d.%m.%Y").txt
/sbin/iptables-save > /home/backup/iptables-save.$HOSTNAME-$(date "+%d.%m.%Y")
# Backup iptables-persistant reboot
/sbin/iptables-save > /etc/iptables/rules.v4
/sbin/ip6tables-save > /etc/iptables/rules.v6 ; /usr/sbin/ip6tables-legacy-save > /etc/iptables/rules_legacy.v6
/sbin/ipset save > /etc/iptables/ipsets
/usr/sbin/netfilter-persistent save
# /sbin/ipset -exist create blacklist hash:ip hashsize 4096
}
function help {
echo -e "\nSyntax: $0 -[L][u] target(s)"
echo -e " ${CGris} Parameters come first. Target is expressed as an IP address.$(tput sgr0)"
echo -e " ${CGris} No specified parameter will ban the IP.$(tput sgr0)"
echo -e " ${txtyel} -L $(tput sgr0)to list currently banned IPs. $(tput sgr0)"
echo -e " ${txtyel} -D $(tput sgr0)to De/unban IP(s). $(tput sgr0)"
echo -e " ${txtyel} -C $(tput sgr0)Check if ip is already ban. $(tput sgr0)"
echo -e " ${txtyel} -U $(tput sgr0)Check Rules & Update ip files & blacklist.$(tput sgr0)"
echo -e " ${txtyel} -S $(tput sgr0)Save all IPs.$(tput sgr0)"
echo -e " ${txtyel} -B $(tput sgr0)Ban list $(tput sgr0)\n"
exit 1
}
#/home/tools/SH/banip.sh $(/home/tools/SH/secu-apache-ban-grep.sh -i)
# If no arguments are passed, call the "help" function.
if [ -z "$1" ]; then
help
fi
# Define some variables
ACTION="-A"
while getopts "hCDLUSBI" OPTION
do
case $OPTION in
h)
help
;;
D)
ACTION="-D"
shift $(($OPTIND - 1))
;;
L)
ACTION="-L"
shift $(($OPTIND - 1))
;;
I)
ACTION="-I"
shift $(($OPTIND - 1))
;;
C)
ACTION="-C"
shift $(($OPTIND - 1))
;;
U)
ACTION="-U"
shift $(($OPTIND - 1))
;;
S)
ACTION="-S"
shift $(($OPTIND - 1))
;;
B)
ACTION="-B"
shift $(($OPTIND - 1))
;;
\?)
help
;;
esac
done
##############################
# Deban ip
if [ $ACTION == "-D" ]; then
for ZTARGET in "$@"
do
ipsetlm=`ipset list Myips | grep "$ZTARGET"`
mylistip=`grep "$ZTARGET" $mybadips`
if [ "$ZTARGET" = "$ipsetlm" ]
then
echo -e " IPSET ${CGris}Myips $(tput sgr0)"
echo -e " $CRouge IP found ($ZTARGET) $txtrst"
ipset del Myips "$ZTARGET"; echo -e " ${Cokvb} REMOVED! ($ZTARGET) $(tput sgr0)"
else
echo -e "\n IPSET : ${CGris}(Myips)\n $Cokvb No ban IP found or already removed! $(tput sgr0)"
fi
echo -en " Myfile: ${CGris}($mybadips)\n"; [ -z "$mylistip" ] && echo -e " $Cokvb ($ZTARGET) NOT found $(tput sgr0)\n" || echo -e " $CRouge IP found ($ZTARGET) $(tput sgr0)\n ${Cokvb} REMOVED! ($ZTARGET) $(tput sgr0)" ; sed -i "/$ZTARGET/d" "$mybadips"
done
exit 1
fi
##############################
# Ban list with /home/tools/SH/secu-apache-ban-grep.sh
if [ $ACTION == "-B" ]; then
# mylistip=$(/home/tools/SH/secu-apache-ban-grep.sh -i)
mylistip=$(/home/tools/SH/secu-apache-grep-log.sh -i)
echo $mylistip
#iptables -I INPUT 1 -m set --match-set Myips src -j DROP
exit
fi
##############################
# Save all ip ipset
if [ $ACTION == "-S" ]; then
/home/tools/SH/iptables-save_all.sh
exit
fi
###############################
# Check if ip is already ban.
if [ $ACTION == "-C" ]; then
#ipset_Myips_check
for ZTARGET in "$@"
do
#check_ipset_ip $1
mylistip=`grep "$ZTARGET" $mybadips | uniq`
# [ -z "$mylistip" ] && echo -e " $CAlert no IP to check, exit!$(tput sgr0)" ; exit 1 || echo -e " $CAlert IP found $(tput sgr0)"
ipsetlm=`ipset list Myips | grep "$ZTARGET"`
if [ "$ZTARGET" = "$ipsetlm" ]
then
echo -e " ${Cok} ${Cokvb} IP ALREADY BAN $txtrst "
echo -e " ${Cok} ${Cokvb} IP FOUND $(tput sgr0) ${CAlert} `ipset list Myips| grep "$ZTARGET"` $(tput sgr0) on ${Jaune} Myips $txtrst "
# ipset list Myips| grep "$ZTARGET"
else
echo -e " ${Cok} ${Cokvb} NO IP found $(tput sgr0) ipset ${CGris}Myips$(tput sgr0)"
fi
[ -z "$mylistip" ] && echo -e " ${Cok} ${Cokvb} NO IP found $(tput sgr0) ${Cok} (${CGris}$mybadips$(tput sgr0))" || echo -e " ${Cok} ${Cokvb} IP FOUND $(tput sgr0) ${CAlert} `grep ${ZTARGET} $mybadips | uniq | wc -L` $(tput sgr0) on ${Jaune} $(echo $mybadips) $(tput sgr0)"
# sed '/^ $ZTARGET/d' $mybadips
done
[ -z `ipset list | grep $ZTARGET | wc -L` ] && echo -e " ${Cok} ${Cokvb} NO IP found on ipset list $(tput sgr0)" || echo -e " ${Cok} ${Cokvb} IP FOUND $(tput sgr0) ${CAlert} `ipset list | grep ${ZTARGET} | wc -L` $(tput sgr0) on ALL ipset list $(tput sgr0)"
#if [ "$ZTARGET" = `ipset list | grep "$ZTARGET"` ]
# then
# echo " Check all list"
# ipset list | grep $ZTARGET
exit 1
fi
if [ $ACTION == "-I" ]; then
echo
echo "$(tput setaf 166)"
date
echo " $(tput sgr0)"
echo
echo -e "$CGris\n##################$(tput sgr0)"
echo -e "$Cokv ipset list Myips $(tput sgr0)\n"
ipset list Myips
echo -e "$CGris\n############################$(tput sgr0)"
fi
###############################
if [ $ACTION == "-L" ]; then
echo
echo "$(tput setaf 166)"
date
echo " $(tput sgr0)"
echo
awk '{print $1}' $mybadips | sort | uniq > $badips
ipset_check_
echo -e "$CGris\n################$(tput sgr0)"
echo -e "$Cokv Rules iptables $(tput sgr0)"
echo -e "$CCyan"
# iptables -L INPUT -v -n | grep DROP | uniq -c | sort
iptables -L INPUT -v -n | grep multiport
iptables -L INPUT -v -n | grep match-set
iptables -L INPUT -v -n | grep "f2b-"
echo -e "$CGris\n################$(tput sgr0)"
echo -e "$Cokv ipset list all $(tput sgr0)\n"
echo -en $txtrst; ipset list | grep "Name:" | head -n1 && echo -en $txtred; ipset list | grep "entries:" | head -n1
echo -en $txtrst; ipset list | grep "Name:" | head -n2 | tail -n1 && echo -en $txtred; ipset list | grep "entries:" | head -n2 | tail -n1
echo -en $txtrst; ipset list | grep "Name:" | head -n3 | tail -n1 && echo -en $txtred; ipset list | grep "entries:" | head -n3 | tail -n1
echo -en $txtrst; ipset list | grep "Name:" | head -n4 | tail -n1 && echo -en $txtred; ipset list | grep "entries:" | head -n4 | tail -n1
# echo -en $txtrst; ipset list | grep "Name:" | head -n5 | tail -n1 && echo -en $txtred; ipset list | grep "entries:" | head -n5 | tail -n1
# echo -e "$Cokv List of MY Personal ip ban $(tput sgr0) $badips ( ${CAlert}`awk '{print $1}' $mybadips | sort | uniq | wc -l` $(tput sgr0) )\n"
# remove first line
# echo -e "$Cokv List of MY Personal ip ban $(tput sgr0) $badips (${CAlert}`awk '{print $1}' $mybadips | sort | uniq | tail -n +2 | wc -l`$(tput sgr0))\n"
# awk '{print $1}' $mybadips | sort | uniq > $badips
# cat $badips
else
# ban work loop
for ZTARGET in "$@"
do
# Check Myips rules in iptables.
# ipset_check_
# ADD entry to Myips
echo -e "$ZTARGET" >> $mybadips
# ipset -exist create Myips hash:ip hashsize 4096 -!
# not verbode with -!
# ipset add Myips "$ZTARGET" -!
ipsetlm=`ipset list Myips | grep "$ZTARGET"`
if [ "$ZTARGET" = "$ipsetlm" ]
then echo -e "$Cok IP ${Cokvb} Already Banned! $(tput sgr0) --> $ZTARGET $(tput sgr0)"
else ipset add Myips "$ZTARGET" -! && echo -en "$Cok IP Banned: `ipset list Myips | grep "$ZTARGET"`$(tput sgr0)\n"
fi
# iptables -I INPUT -m set --match-set Myips src -j DROP
# let's go to ban (iptables)
# Uncomment this if you want to use iptables!
# echo $txtcya"Applying action $txtred$ACTION$txtcya to $txtyel$ZTARGET"$txtrst
# iptables $ACTION INPUT -s $ZTARGET -j DROP
done
fi
##############################
if [ $ACTION == "-U" ]; then
echo -e "\n"
ipset_check_
echo -e "\n${CGris}Make clean log (remove blank line) on$(tput sgr0) $mybadips"
echo -e " Before (`cat $mybadips | wc -l`) lines."
sed -i '/^$/d' $mybadips
echo -e "$Cok After (`cat $mybadips | wc -l`) lines.\n"
echo -e "\n$txtcya Populate Blacklist $txtrst"
echo -e "$(tput sgr0)\n"
fi
#####################################################
#iptables -I INPUT -m set --match-set Myips src -j DROP
#iptables -I INPUT -m set --match-set blockip src -j DROP
#iptables -I INPUT -m set --match-set portsentry src -j DROP
######################################################
updateblacklist() {
echo -e "\n$txtcya Populate Date$txtrst"
/etc/ipset-blacklist/update-blacklist.sh /etc/ipset-blacklist/ipset-blacklist.conf
echo -e "...$(tput sgr0)"
# echo $txtcya"Applying action $txtred$ACTION$txtcya to $txtyel$ZTARGET"$txtrst
# iptables $ACTION INPUT -s $ZTARGET -j DROP
}
secu bash ip iptables
<iframe width="100%" height="8246" src="https://snippet.echosystem.fr?embed=618aaf8632175" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 09/11/2021
[fail2ban] EXCLUDE your ip in jail
#!/bin/sh
# debaniptuff.sh
# by E32
monipamoi="66.66.66.66"
MONFILE="/etc/fail2ban/jail.local"
echo -e "\n Script: $0 \n"
[[ -z "$1" ]] && echo " [ADD IP] $monipamoi to $MONFILE" || monipamoi=$1
# && echo " ADD IP: $monipamoi"
# Check si le fichier existe !
if [[ -f $MONFILE ]];then
echo " ✅$MONFILE exists"
else
echo " ⛔️$MONFILE doesn't exist"
exit 1
fi
pyestonsed() {
sed -i "/ignoreip /c\ignoreip = 127.0.0.1 192.168.1.0/24 $monipamoi" /etc/fail2ban/jail.local
}
backupfile() {
#On backup avant de tout nicker
cp /etc/fail2ban/jail.local /etc/fail2ban/jail.local_backup
}
# On execute le bourdel
# Check si la ligfne à modifier exist
# -x, --line-regexp
# Select only those matches that exactly match the whole line.
# -q, --quiet, --silent
if grep -q ignoreip "$MONFILE"
then
echo " ✅ OK let's go Baby"
[[ -z "$monipamoi" ]] && echo " NO IP provided ... exit script !" ; exit 1 || echo " ADD IP: $monipamoi"
backupfile
pyestonsed
else
echo " ⛔️ NO code to modify found"
exit 1
fi
#
echo -e "\n ✅remplacement IP: ${monipamoi} [OK]\n"
fail2ban ip shell
<iframe width="100%" height="1118" src="https://snippet.echosystem.fr?embed=618145aa31373" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 03/11/2021
Location IP - ipinfodb.com
function detect_city($ip) {
$default = 'UNKNOWN';
if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost')
$ip = '8.8.8.8';
$curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';
$url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip);
$ch = curl_init();
$curl_opt = array(
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERAGENT => $curlopt_useragent,
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 1,
CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
);
curl_setopt_array($ch, $curl_opt);
$content = curl_exec($ch);
if (!is_null($curl_info)) {
$curl_info = curl_getinfo($ch);
}
curl_close($ch);
if ( preg_match('{<li>City : ([^<]*)</li>}i', $content, $regs) ) {
$city = $regs[1];
}
if ( preg_match('{<li>State/Province : ([^<]*)</li>}i', $content, $regs) ) {
$state = $regs[1];
}
if( $city!='' && $state!='' ){
$location = $city . ', ' . $state;
return $location;
}else{
return $default;
}
}
ip php
https://codepad.co/snippet/9fb3cd
<iframe width="100%" height="1028" src="https://snippet.echosystem.fr?embed=5a955ce19b4a0" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 09/11/2021
[PHP] get IP
<?php
$ip = getenv('REMOTE_ADDR'); /* get ip address */
echo "<br/>";
echo ' ip Address is ' .$_ENV["REMOTE_ADDR"] . '!'; /* print ip address */
?>
ip php
<iframe width="100%" height="272" src="https://snippet.echosystem.fr?embed=5a9558f3ed738" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 07/09/2021
[SHELL] Show ip debîan
#!/bin/sh
#
# Show ip debîan (9/10) for 2 interfaces (eth0, eth1)
# ipv4
hostname --ip-address | awk '{ print $2 }'
# ipv6
hostname --ip-address | awk '{ print $1 }'
# OR
ip=`hostname --ip-address`
echo $ip
bash ip shell
echosystem.fr
<iframe width="100%" height="488" src="https://snippet.echosystem.fr?embed=5980ef59459ab" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 09/11/2021
Code source IP detect
<?php
header('Content-Type: text/html; charset=iso-8859-1');
$ipaddress = $_SERVER['REMOTE_ADDR']; //ip address
$host = gethostbyaddr($ipaddress);
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$realip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$realip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$realip=$_SERVER['REMOTE_ADDR'];
}
//echo "$ipaddress;$realip;$host;";
$locationstr="http://ip-api.com/xml/";
$locationstr = $locationstr.$ipaddress;
//loading the xml file directly from the website
$xml = simplexml_load_file($locationstr);
$countrycode = $xml->countryCode; //country code
$countryname = $xml->country; //country name
$region = $xml->regionName; //region name
$city = $xml->city; //city name
$lattitude = $xml->lat; //city latitude
$longitude = $xml->lon; //city longitude
$isp = $xml->isp; //city latitude
$noeud = $xml->as; //city longitude
//$browsername = $xml->browserName; //browser name
?>
<div class="main" style="width:950px;">
<h2 class="post-title">Voici votre adresse IP locale : <b><?php //echo $ipaddress; ?></b></h2>
<h2 class="post-title">Voici votre adresse IP publique : <b><?php //echo $ipaddress; ?></b></h2>
<h2 class="post-title">Voici votre nom d'hôte : <b><?php echo $host; ?></b></h2>
Cette adresse a été localisée dans la belle ville de <b><?php echo $city ?></b> (Région : <?php echo $region ?> / Pays : <?php echo $countryname ?>)
<br/>(Localisation effectuée en fonction de votre FAI (<b><?php echo $isp; ?></b>) et du noeud réseau auquel vous êtes rattaché (<b><?php echo $noeud; ?></b>))
<p>
<center>
<iframe width="900" height="550"frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?key=AIzaSyCRTD-ARSWquI_i1P0AlZrRPxnzmtIntd4&q=<?php echo $lattitude?>,<?php echo $longitude?>&zoom=12" allowfullscreen>
</iframe></center>
</p>
Passez une excellente journée.
<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
<script>
//get the IP addresses associated with an account
function getIPs(callback){
var ip_dups = {};
//compatibility for firefox and chrome
var RTCPeerConnection = window.RTCPeerConnection
|| window.mozRTCPeerConnection
|| window.webkitRTCPeerConnection;
var useWebKit = !!window.webkitRTCPeerConnection;
//bypass naive webrtc blocking using an iframe
if(!RTCPeerConnection){
//NOTE: you need to have an iframe in the page right above the script tag
//
//<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
//<script>...getIPs called in here...
//
var win = iframe.contentWindow;
RTCPeerConnection = win.RTCPeerConnection
|| win.mozRTCPeerConnection
|| win.webkitRTCPeerConnection;
useWebKit = !!win.webkitRTCPeerConnection;
}
//minimal requirements for data connection
var mediaConstraints = {
optional: [{RtpDataChannels: true}]
};
var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
//construct a new RTCPeerConnection
var pc = new RTCPeerConnection(servers, mediaConstraints);
function handleCandidate(candidate){
//match just the IP address
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
var ip_addr = ip_regex.exec(candidate)[1];
//remove duplicates
if(ip_dups[ip_addr] === undefined)
callback(ip_addr);
ip_dups[ip_addr] = true;
}
//listen for candidate events
pc.onicecandidate = function(ice){
//skip non-candidate events
if(ice.candidate)
handleCandidate(ice.candidate.candidate);
};
//create a bogus data channel
pc.createDataChannel("");
//create an offer sdp
pc.createOffer(function(result){
//trigger the stun server request
pc.setLocalDescription(result, function(){}, function(){});
}, function(){});
//wait for a while to let everything done
setTimeout(function(){
//read candidate info from local description
var lines = pc.localDescription.sdp.split('\n');
lines.forEach(function(line){
if(line.indexOf('a=candidate:') === 0)
handleCandidate(line);
});
}, 1000);
}
//insert IP addresses into the page
getIPs(function(ip){
var b = document.createElement("b");
b.textContent = ip + ' ';
if (ip.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/))
//document.write(ip);
document.getElementsByTagName("h2")[0].appendChild(b);
else if (ip.match(/^[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7}$/))
//document.write(ip);
document.getElementsByTagName("h2")[2].appendChild(b);
else
// document.write(ip);
document.getElementsByTagName("h2")[1].appendChild(b);
}
);
</script>
</div>
ip php
ip-api.com
<iframe width="100%" height="2504" src="https://snippet.echosystem.fr?embed=55b1da5fcfe50" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 09/11/2021
[JS] IP Address
<SCRIPT LANGUAGE="JavaScript">
var ip = '<!--#echo var="REMOTE_ADDR"-->';
document.write("Your IP address is" + ip);
</script>
ip js
<iframe width="100%" height="254" src="https://snippet.echosystem.fr?embed=52ef6df7c4623" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 09/11/2021
[JS] Calendar
Calendar
This is a plain and simple monthly calendar. It's formatted with styles sheets so the appearance can easily be changed. In the head of your document, add the following style sheet and JavaScript code:
<style type="text/css">
span.label {color:black;width:30;height:16;text-align:center;margin-top:0;background:#ffF;font:bold 13px Arial}
span.c1 {cursor:hand;color:black;width:30;height:16;text-align:center;margin-top:0;background:#ffF;font:bold 13px Arial}
span.c2 {cursor:hand;color:red;width:30;height:16;text-align:center;margin-top:0;background:#ffF;font:bold 13px Arial}
span.c3 {cursor:hand;color:#b0b0b0;width:30;height:16;text-align:center;margin-top:0;background:#ffF;font:bold 12px Arial}
</style>
<script type="text/javascript">
function maxDays(mm, yyyy){
var mDay;
if((mm == 3) || (mm == 5) || (mm == 8) || (mm == 10)){
mDay = 30;
}
else{
mDay = 31
if(mm == 1){
if (yyyy/4 - parseInt(yyyy/4) != 0){
mDay = 28
}
else{
mDay = 29
}
}
}
return mDay;
}
function changeBg(id){
if (eval(id).style.backgroundColor != "yellow"){
eval(id).style.backgroundColor = "yellow"
}
else{
eval(id).style.backgroundColor = "#ffffff"
}
}
function writeCalendar(){
var now = new Date
var dd = now.getDate()
var mm = now.getMonth()
var dow = now.getDay()
var yyyy = now.getFullYear()
var arrM = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
var arrY = new Array()
for (ii=0;ii<=4;ii++){
arrY[ii] = yyyy - 2 + ii
}
var arrD = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
var text = ""
text = "<form name=calForm>"
text += "<table border=1>"
text += "<tr><td>"
text += "<table width=100%><tr>"
text += "<td align=left>"
text += "<select name=selMonth onChange='changeCal()'>"
for (ii=0;ii<=11;ii++){
if (ii==mm){
text += "<option value= " + ii + " Selected>" + arrM[ii] + "</option>"
}
else{
text += "<option value= " + ii + ">" + arrM[ii] + "</option>"
}
}
text += "</select>"
text += "</td>"
text += "<td align=right>"
text += "<select name=selYear onChange='changeCal()'>"
for (ii=0;ii<=4;ii++){
if (ii==2){
text += "<option value= " + arrY[ii] + " Selected>" + arrY[ii] + "</option>"
}
else{
text += "<option value= " + arrY[ii] + ">" + arrY[ii] + "</option>"
}
}
text += "</select>"
text += "</td>"
text += "</tr></table>"
text += "</td></tr>"
text += "<tr><td>"
text += "<table border=1>"
text += "<tr>"
for (ii=0;ii<=6;ii++){
text += "<td align=center><span class=label>" + arrD[ii] + "</span></td>"
}
text += "</tr>"
aa = 0
for (kk=0;kk<=5;kk++){
text += "<tr>"
for (ii=0;ii<=6;ii++){
text += "<td align=center><span id=sp" + aa + " onClick='changeBg(this.id)'>1</span></td>"
aa += 1
}
text += "</tr>"
}
text += "</table>"
text += "</td></tr>"
text += "</table>"
text += "</form>"
document.write(text)
changeCal()
}
function changeCal(){
var now = new Date
var dd = now.getDate()
var mm = now.getMonth()
var dow = now.getDay()
var yyyy = now.getFullYear()
var currM = parseInt(document.calForm.selMonth.value)
var prevM
if (currM!=0){
prevM = currM - 1
}
else{
prevM = 11
}
var currY = parseInt(document.calForm.selYear.value)
var mmyyyy = new Date()
mmyyyy.setFullYear(currY)
mmyyyy.setMonth(currM)
mmyyyy.setDate(1)
var day1 = mmyyyy.getDay()
if (day1 == 0){
day1 = 7
}
var arrN = new Array(41)
var aa
for (ii=0;ii<day1;ii++){
arrN[ii] = maxDays((prevM),currY) - day1 + ii + 1
}
aa = 1
for (ii=day1;ii<=day1+maxDays(currM,currY)-1;ii++){
arrN[ii] = aa
aa += 1
}
aa = 1
for (ii=day1+maxDays(currM,currY);ii<=41;ii++){
arrN[ii] = aa
aa += 1
}
for (ii=0;ii<=41;ii++){
eval("sp"+ii).style.backgroundColor = "#FFFFFF"
}
var dCount = 0
for (ii=0;ii<=41;ii++){
if (((ii<7)&&(arrN[ii]>20))||((ii>27)&&(arrN[ii]<20))){
eval("sp"+ii).innerHTML = arrN[ii]
eval("sp"+ii).className = "c3"
}
else{
eval("sp"+ii).innerHTML = arrN[ii]
if ((dCount==0)||(dCount==6)){
eval("sp"+ii).className = "c2"
}
else{
eval("sp"+ii).className = "c1"
}
if ((arrN[ii]==dd)&&(mm==currM)&&(yyyy==currY)){
eval("sp"+ii).style.backgroundColor="#90EE90"
}
}
dCount += 1
if (dCount>6){
dCount=0
}
}
}
</script>
Then, in the body of your document, add the following where you want the calendar to show up:
<script type="text/javascript">writeCalendar()</script>
html ip js
<iframe width="100%" height="3314" src="https://snippet.echosystem.fr?embed=52ef6d41f205f" type="text/html"></iframe>
Texte seul - Permalink - Snippet public posté le 02/11/2021