#!/bin/bash # - ip , IP="$1"; # IP NSLOOKUP, GREP SED # hostname=$(nslookup $IP | grep -m 1 "name" | sed 's|.*= ||'|sed -r 's/ Auth.+//' | sed 's/^[ \t]*//;s/[ \t]*$//' ); # NSLOOKUP , # IP whois, # GREP SED if [[ "$hostname" == '' ]]; then hostname=$(whois $IP | grep -m 1 "owner\|OrgName\|orgname\|NetName\|netname\|origin" | sed 's|.*: ||'|sed -r 's/. Auth.+//' | sed 's/^[ \t]*//;s/[ \t]*$//') fi # echo "$hostname" exit 0;
gethost.sh ip_address
$result=mysql_query($queryOneIpaddressTraffic) or die (mysql_error()); $numrow=1; $totalmb=0; while ($line = mysql_fetch_array($result,MYSQL_NUM)) { echo "<tr>"; echo "<td>".$numrow."</td>"; if($enableUseiconv==1) $line[0]=iconv("CP1251","UTF-8",urldecode($line[0])); echo "<td><a href='http://".$line[0]."' target=blank>".$line[0]."</a></td>";
//, HTTPS ( ':') // , HTTP , $dv=strpos($line[0], ":") ; if ($dv < 1) { echo "<td><a href='http://".$line[0]."' target=blank>".$line[0]."</a></td>"; } else { // ':' , HTTPS , // "" ... // IP , .. ':' $str1=strpos($line[0], ":"); $row1=substr($line[0], 0, $str1); $ipaddress = ltrim($ipaddress); $ipaddress = $row1; // IP gethost.sh $hostname = shell_exec('/usr/bin/gethost.sh ' . $ipaddress); // IP echo "<td><a href='https://".$ipaddress."' target=blank>".$hostname."</a></td>"; }
Additions:
//, HTTPS ( ':') // , HTTP , $dv=strpos($line[0], ":") ; if ($dv < 1) { echo "<td><a href='http://".$line[0]."' target=blank>".$line[0]."</a></td>"; } else { // ':' , HTTPS , // "" ... // IP , .. ':' $str1=strpos($line[0], ":"); $row1=substr($line[0], 0, $str1); $ipaddress = ltrim($ipaddress); $ipaddress = $row1; // IP /////////////////////////////////////////////////////////// $options = array( "ssl" => array( "capture_peer_cert" => true, "capture_peer_chain" => true, "capture_peer_cert_chain" => false, "verify_peer" => false, "verify_peer_name" => false, "allow_self_signed" => false ) ); $get = stream_context_create($options); $read = stream_socket_client("ssl://".$ipaddress.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get); $cert = stream_context_get_params($read); $certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']); $certinfo = $certinfo['name']; $CN=strpos($certinfo,"CN=")+3; $CN_end=strlen($certinfo); $hostname = substr($certinfo, $CN, $CN_end); //////////////////////////////////////////////////////////// // IP echo "<td><a href='https://".$ipaddress."' target=blank>".$hostname."</a></td>"; }
Source: https://habr.com/ru/post/307686/
All Articles