라이브러리

[PHP] net_get_interfaces - 네트워크 인터페이스 가져오기




PHP에서 net_get_interfaces 사용하기

`net_get_interfaces` 함수는 PHP 7.2 이상에서 사용할 수 있는 내장 함수입니다. 이 함수는 시스템의 네트워크 인터페이스 목록을 반환합니다.

사용법


`net_get_interfaces` 함수는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

$result = net_get_interfaces();



반환값


`net_get_interfaces` 함수는 다음 형식의 배열을 반환합니다.

#hostingforum.kr
php

array (

  'lo' => array (

    'flags' => 6724,

    'mtu' => 65536,

    'bytes' => 0,

    'packets' => 0,

    'errin' => 0,

    'errout' => 0,

    'dropin' => 0,

    'dropout' => 0,

    'fifo' => 0,

    'txqueuelen' => 0,

    'rxqueuelen' => 0,

    'tx_bytes' => 0,

    'tx_packets' => 0,

    'tx_errs' => 0,

    'tx_dropped' => 0,

    'tx_fifo_errors' => 0,

    'tx_collisions' => 0,

    'tx_carrier_errors' => 0,

    'tx_frame_errors' => 0,

    'rx_bytes' => 0,

    'rx_packets' => 0,

    'rx_errs' => 0,

    'rx_dropped' => 0,

    'rx_fifo_errors' => 0,

    'rx_length_errors' => 0,

    'rx_over_errors' => 0,

    'rx_crc_errors' => 0,

    'rx_frame_errors' => 0,

    'rx_fifo_errors' => 0,

    'tx_aborted_errors' => 0,

    'mtu_mismatch_error' => 0,

    'rx_length_errors' => 0,

    'rx_over_errors' => 0,

    'rx_crc_errors' => 0,

    'rx_frame_errors' => 0,

    'collisions' => 0,

    'tx_window_errors' => 0,

    'tx_fifo_errors' => 0,

    'tx_heartbeat_errors' => 0,

    'rx_window_errors' => 0,

    'rx_fifo_errors' => 0,

    'tx_aborted_errors' => 0,

    'carrier_errors' => 0,

    'tx_window_errors' => 0,

    'tx_heartbeat_errors' => 0,

  ),

  'eth0' => array (

    'flags' => 6724,

    'mtu' => 1500,

    'bytes' => 0,

    'packets' => 0,

    'errin' => 0,

    'errout' => 0,

    'dropin' => 0,

    'dropout' => 0,

    'fifo' => 0,

    'txqueuelen' => 1000,

    'rxqueuelen' => 1000,

    'tx_bytes' => 0,

    'tx_packets' => 0,

    'tx_errs' => 0,

    'tx_dropped' => 0,

    'tx_fifo_errors' => 0,

    'tx_collisions' => 0,

    'tx_carrier_errors' => 0,

    'tx_frame_errors' => 0,

    'rx_bytes' => 0,

    'rx_packets' => 0,

    'rx_errs' => 0,

    'rx_dropped' => 0,

    'rx_fifo_errors' => 0,

    'rx_length_errors' => 0,

    'rx_over_errors' => 0,

    'rx_crc_errors' => 0,

    'rx_frame_errors' => 0,

    'rx_fifo_errors' => 0,

    'tx_aborted_errors' => 0,

    'mtu_mismatch_error' => 0,

    'rx_length_errors' => 0,

    'rx_over_errors' => 0,

    'rx_crc_errors' => 0,

    'rx_frame_errors' => 0,

    'collisions' => 0,

    'tx_window_errors' => 0,

    'tx_fifo_errors' => 0,

    'tx_heartbeat_errors' => 0,

    'rx_window_errors' => 0,

    'rx_fifo_errors' => 0,

    'tx_aborted_errors' => 0,

    'carrier_errors' => 0,

    'tx_window_errors' => 0,

    'tx_heartbeat_errors' => 0,

  ),

)



예제


#hostingforum.kr
php

$result = net_get_interfaces();



foreach ($result as $interface => $stats) {

    echo "인터페이스: $interface
";

    echo "MTU: $stats[mtu]
";

    echo "바이트: $stats[bytes]
";

    echo "패킷: $stats[packets]
";

    echo "에러인: $stats[errin]
";

    echo "에러아웃: $stats[errout]
";

    echo "드롭인: $stats[dropin]
";

    echo "드롭아웃: $stats[dropout]
";

    echo "TX 큐 길이: $stats[txqueuelen]
";

    echo "RX 큐 길이: $stats[rxqueuelen]
";

    echo "TX 바이트: $stats[tx_bytes]
";

    echo "TX 패킷: $stats[tx_packets]
";

    echo "TX 에러: $stats[tx_errs]
";

    echo "TX 드롭: $stats[tx_dropped]
";

    echo "TX FIFO 에러: $stats[tx_fifo_errors]
";

    echo "TX 충돌: $stats[tx_collisions]
";

    echo "TX 캐리어 에러: $stats[tx_carrier_errors]
";

    echo "TX 프레임 에러: $stats[tx_frame_errors]
";

    echo "RX 바이트: $stats[rx_bytes]
";

    echo "RX 패킷: $stats[rx_packets]
";

    echo "RX 에러: $stats[rx_errs]
";

    echo "RX 드롭: $stats[rx_dropped]
";

    echo "RX FIFO 에러: $stats[rx_fifo_errors]
";

    echo "RX 길이 에러: $stats[rx_length_errors]
";

    echo "RX 오버 에러: $stats[rx_over_errors]
";

    echo "RX CRC 에러: $stats[rx_crc_errors]
";

    echo "RX 프레임 에러: $stats[rx_frame_errors]
";

    echo "충돌: $stats[collisions]
";

    echo "TX 윈도우 에러: $stats[tx_window_errors]
";

    echo "TX FIFO 에러: $stats[tx_fifo_errors]
";

    echo "TX 하트비트 에러: $stats[tx_heartbeat_errors]
";

    echo "RX 윈도우 에러: $stats[rx_window_errors]
";

    echo "RX FIFO 에러: $stats[rx_fifo_errors]
";

    echo "TX 아보트 에러: $stats[tx_aborted_errors]
";

    echo "캐리어 에러: $stats[carrier_errors]
";

    echo "TX 윈도우 에러: $stats[tx_window_errors]
";

    echo "TX 하트비트 에러: $stats[tx_heartbeat_errors]
";

    echo "
";

}



이 예제는 `net_get_interfaces` 함수의 반환값을 반복하여 각 인터페이스에 대한 통계를 출력합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 372 페이지

검색

게시물 검색