• 21-02-2015, 15:23:41
    #1
    Merhabalar

    $cikti = shell_exec("sudo netstat -an | grep 192.168.1.1:2020 | grep ESTABLISHED | awk '{print $5}' | cut -d: -f1");
    echo $cikti;
    yapinca ekranda aldigim ip adresleri bu sekilde cikiyor.

    192.168.1.250 192.168.1.42 192.168.1.36 192.168.1.61
    Bu IP adreslerini sirayla mysql sorgusuyla sorup detaylari tabloda listelemek istiyorum. Fakat sorun su ki mysql sorgusuna ip'ler teker teker degil toplu sekilde geliyor. IP adreslerini en iyi hangi sekilde teker teker mysql sorgusuna iletebilirim?


    Tablo bu sekilde
    			<table class="listtable" cellspacing="0">
    				<thead>
    					<tr>
    						<th><h3>Username</h3></th>
    						<th><h3>Channel</h3></th>
    						<th><h3>IP</h3></th>
    						<th><h3>Location</h3></th>
    						<th><h3>User Agent</h3></th>
    						<th><h3>Date Started</h3></th>
    						<th><h3>Online Time</h3></th>
    						<th><h3>Options</h3></th>
    					</tr>
    				</thead>
    				<?php
    include('config/mysql.php');
    $result = mysql_query("SELECT * FROM connected_clients WHERE ip = $cikti ORDER BY id DESC LIMIT 1");
    echo mysql_error();
    while ($row = mysql_fetch_array($result)) { 
    
    $connection = $row["status"];
    $username = $row["user"];
    $channel = $row["port"];
    $ipaddress = $row["ip"];
    $useragent = $row["useragent"];
    $start_time = $row["time-in"];
    $dateend = $row["time-out"];
    $timeonline = get_time_difference($start_time, $end_time);
    $bandwidth = $row["bandwidth"];
    ?>
    
    				<tbody>
    					<tr>
    						<td><?php echo $username ?></td>
    						<td><?php echo $channel ?></td>
    						<td><?php echo $ipaddress ?></td>
    						<td><?php echo $isp ?></td>
    						<td><?php echo $useragent ?></td>
    						<td><?php echo $start_time ?></td>
    						<td><?php echo $timeonline ?></td>
    						<td>Delete</td>
    						<?php } ?>
    					</tr>
     				</tbody>
    			</table>
    Yardiminiz icin simdiden tesekkürler
  • 21-02-2015, 16:21:15
    #2
    <?php
    $ipler = array();
    $cikti = shell_exec("sudo netstat -an | grep 192.168.1.1:2020 | grep ESTABLISHED | awk '{print $5}' | cut -d: -f1");
    list($ip1, $ip2, $ip3) = explode(" ", $cikti);
    array_push($ipler, $ip1);
    array_push($ipler, $ip2);
    array_push($ipler, $ip3);
    ?>

    Bı şekilde ipleri bir arraya alıp, foreach döngüsü kullanarak ekrana basabilirsin.
  • 21-02-2015, 16:25:03
    #3
    çıktıyı döngüye sokup veritabanına kayıt edebilirsin ama çıktı toplu şekilde mi çıkıyor yoksa dizi olarak mı veriyor. birde ip adresleri 192 ile mi baslıyor hep baslamıyorsa bile çıktıyı diziye dönüştürüp döngüye sokulup veritabanına kayıt edilebilir.
  • 21-02-2015, 20:20:41
    #4
    Ceu adlı üyeden alıntı: mesajı görüntüle
    <?php
    $ipler = array();
    $cikti = shell_exec("sudo netstat -an | grep 192.168.1.1:2020 | grep ESTABLISHED | awk '{print $5}' | cut -d: -f1");
    list($ip1, $ip2, $ip3) = explode(" ", $cikti);
    array_push($ipler, $ip1);
    array_push($ipler, $ip2);
    array_push($ipler, $ip3);
    ?>

    Bı şekilde ipleri bir arraya alıp, foreach döngüsü kullanarak ekrana basabilirsin.
    ufukt51 adlı üyeden alıntı: mesajı görüntüle
    çıktıyı döngüye sokup veritabanına kayıt edebilirsin ama çıktı toplu şekilde mi çıkıyor yoksa dizi olarak mı veriyor. birde ip adresleri 192 ile mi baslıyor hep baslamıyorsa bile çıktıyı diziye dönüştürüp döngüye sokulup veritabanına kayıt edilebilir.

    Cevaplariniz icin tesekkürler.

    $cikti ip'leri yan yana siraliyor yani "192.168.1.50 192.168.1.61 192.168.1.63"


    $cikti = shell_exec("sudo netstat -an | grep $ip:$port | grep ESTABLISHED | awk '{print $5}' | cut -d: -f1");
    $ips = explode(" ",$cikti);
    echo $ips[0]; 
    echo "test";
    echo $ips[1];
    
    foreach($ips as $onlineip)
    {	
    	echo "Online: $onlineip <hr />";
    }
    bu sekilde $ips[0] hala "192.168.1.50 192.168.1.61 192.168.1.63" seklinde gösteriyor ama aslinda sadece 192.168.1.50 göstermesi gerekir.

    $ips = explode(" ",$cikti); yerine $ips = explode(" ",'192.168.1.50 192.168.1.61 192.168.1.63'); yazinca $ips[0] 192.168.1.50 ve $ips[1] 192.168.1.61 gösteriyor. Dogrusu olanda bu ama sorun nerde bilmiyorum. Umarim yardimci olabilirsiniz
  • 22-02-2015, 03:04:59
    #5
    <?php
    $ver = shell_exec("sudo netstat -an | grep $ip:$port | grep ESTABLISHED | awk '{print $5}' | cut -d: -f1");
    preg_match_all("!(?:[0-9]{1,3}\.){3}[0-9]{1,3}!si", $ver, $cikti);
    foreach ($cikti[0] as $yazdir) {
        echo "Online: $yazdir<hr />";
    }
    ?>

    İşine yarar umarım

    Edit :
    <table class="listtable" cellspacing="0"> 
        <thead> 
            <tr> 
                <th><h3>Username</h3></th> 
                <th><h3>Channel</h3></th> 
                <th><h3>IP</h3></th> 
                <th><h3>Location</h3></th> 
                <th><h3>User Agent</h3></th> 
                <th><h3>Date Started</h3></th> 
                <th><h3>Online Time</h3></th> 
                <th><h3>Options</h3></th> 
            </tr> 
    </thead> 
    <?php
    include('config/mysql.php');
    $ver = shell_exec("sudo netstat -an | grep $ip:$port | grep ESTABLISHED | awk '{print $5}' | cut -d: -f1");
    preg_match_all("!(?:[0-9]{1,3}\.){3}[0-9]{1,3}!si", $ver, $cikti);
    $birlestir = implode(",", $cikti[0]);
    $result = mysql_query("SELECT * FROM connected_clients WHERE ip IN (" . $birlestir . ") ORDER BY id DESC");
    while ($row = mysql_fetch_array($result)) {
    
        $connection = $row["status"];
        $username = $row["user"];
        $channel = $row["port"];
        $ipaddress = $row["ip"];
        $useragent = $row["useragent"];
        $start_time = $row["time-in"];
        $dateend = $row["time-out"];
        $timeonline = get_time_difference($start_time, $end_time);
        $bandwidth = $row["bandwidth"];
        ?> 
    
        <tbody> 
            <tr> 
                <td><?php echo $username ?></td> 
                <td><?php echo $channel ?></td> 
                <td><?php echo $ipaddress ?></td> 
                <td><?php echo $isp ?></td> 
                <td><?php echo $useragent ?></td> 
                <td><?php echo $start_time ?></td> 
                <td><?php echo $timeonline ?></td> 
                <td>Delete</td> 
            <?php } ?> 
        </tr> 
    </tbody> 
    </table>
  • 22-02-2015, 15:11:58
    #6
    onurkun adlı üyeden alıntı: mesajı görüntüle
    <?php
    $ver = shell_exec("sudo netstat -an | grep $ip:$port | grep ESTABLISHED | awk '{print $5}' | cut -d: -f1");
    preg_match_all("!(?:[0-9]{1,3}\.){3}[0-9]{1,3}!si", $ver, $cikti);
    foreach ($cikti[0] as $yazdir) {
        echo "Online: $yazdir<hr />";
    }
    ?>

    İşine yarar umarım

    Edit :
    <table class="listtable" cellspacing="0"> 
        <thead> 
            <tr> 
                <th><h3>Username</h3></th> 
                <th><h3>Channel</h3></th> 
                <th><h3>IP</h3></th> 
                <th><h3>Location</h3></th> 
                <th><h3>User Agent</h3></th> 
                <th><h3>Date Started</h3></th> 
                <th><h3>Online Time</h3></th> 
                <th><h3>Options</h3></th> 
            </tr> 
    </thead> 
    <?php
    include('config/mysql.php');
    $ver = shell_exec("sudo netstat -an | grep $ip:$port | grep ESTABLISHED | awk '{print $5}' | cut -d: -f1");
    preg_match_all("!(?:[0-9]{1,3}\.){3}[0-9]{1,3}!si", $ver, $cikti);
    $birlestir = implode(",", $cikti[0]);
    $result = mysql_query("SELECT * FROM connected_clients WHERE ip IN (" . $birlestir . ") ORDER BY id DESC");
    while ($row = mysql_fetch_array($result)) {
    
        $connection = $row["status"];
        $username = $row["user"];
        $channel = $row["port"];
        $ipaddress = $row["ip"];
        $useragent = $row["useragent"];
        $start_time = $row["time-in"];
        $dateend = $row["time-out"];
        $timeonline = get_time_difference($start_time, $end_time);
        $bandwidth = $row["bandwidth"];
        ?> 
    
        <tbody> 
            <tr> 
                <td><?php echo $username ?></td> 
                <td><?php echo $channel ?></td> 
                <td><?php echo $ipaddress ?></td> 
                <td><?php echo $isp ?></td> 
                <td><?php echo $useragent ?></td> 
                <td><?php echo $start_time ?></td> 
                <td><?php echo $timeonline ?></td> 
                <td>Delete</td> 
            <?php } ?> 
        </tr> 
    </tbody> 
    </table>
    Cok tesekkürler. Ilk verdiginiz örnek calisiyor. Fakat ikincisinde mysql sorgusuna gelen ip'ler dogru oldugu halde calismiyor. Herhangi bir hata'da göstermiyor.
  • 22-02-2015, 16:30:19
    #7
    Kimlik doğrulama veya yönetimden onay bekliyor.
    inanbayram adlı üyeden alıntı: mesajı görüntüle
    Cok tesekkürler. Ilk verdiginiz örnek calisiyor. Fakat ikincisinde mysql sorgusuna gelen ip'ler dogru oldugu halde calismiyor. Herhangi bir hata'da göstermiyor.
    Hocam exec(); fonksiyonunu kullanmanız daha iyi olur gibime geliyor. Shell_exec arasındaki fark ise verileri dizi olarak döndürmesi. Windows'ta işlem listesini aldım. Çıktılar aşağıdaki gibi.

    shell_exec;


    exec;
  • 22-02-2015, 16:34:21
    #8
    Kimlik doğrulama veya yönetimden onay bekliyor.
    bu fonksiyonları shared alanda kullanmamanız güvenlik anlamında yararınıza olacaktır.