Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Funkcja ip2mac
Forum PHP.pl > Forum > Gotowe rozwiązania > Algorytmy, klasy, funkcje
Nightwalker
Dzięki tej funkcji możemy zamienić numer IP na numer karty sieciowej mac, oczywiscie dziala to tylko, na komputery , ktore są w sieci LAN.
Funkcja przeznaczona dla systemów POSIX (Unix, Linux, *BSD itp), wymaga programu arping

  1. <?php
  2.  
  3. /*
  4.  $id: ip2mac.php, v 0.1 2006/02/13 23:32 Nightwalker <nightwalker@rootnode.eu> Exp $
  5.  
  6.  Relased on BSD License
  7.  
  8.  Copyright (c) 2007, Nightwalker
  9.  All rights reserved.
  10.  
  11.  Redistribution and use in source and binary forms, with or without
  12.  modification, are permitted provided that the following conditions are met:
  13.  
  14. * Redistributions of source code must retain the above copyright notice,
  15. this list of conditions and the following disclaimer.
  16. * Redistributions in binary form must reproduce the above copyright notice,
  17. this list of conditions and the following disclaimer in the documentation
  18. and/or other materials provided with the distribution.
  19. * Neither the name of the <ORGANIZATION> nor the names of its contributors
  20. may be used to endorse or promote products derived from this software
  21. without specific prior written permission.
  22.  
  23. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. POSSIBILITY OF SUCH DAMAGE.
  35.  
  36.  Usage example:
  37.  
  38. ip2mac( "192.168.4.128", "eth1" );
  39. */
  40.  
  41. function ip2mac( $ip, $ifc )
  42. {
  43. # path to arping.
  44. $arping = "/sbin/arping";
  45.  
  46. # arguments for arping.
  47. $args  = " -c 1 -I {$ifc} {$ip} -f";
  48.  
  49. exec( $arping . $args . " | grep -o ..:..:..:..:..:..", $response );
  50.  
  51. return $response[0];
  52. }
  53.  
  54. ?>
ActivePlayer
hm to jakas skomplikowana powłoka do funkcji exec?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.