2011-01-11 2 views
0

나는대역폭 계산 (인터넷 데이터 전송)

그것은 작동 대역폭을 얻기 위해 다음 코드를 사용했다하지만 난

1.I 전체 인터넷 데이터는 MB에 전송해야합니다, 내가 어떻게 변환합니까 의심

다음습니까? , 전송 된 총 데이터 (다운로드 + 업로드)는 다른 대역폭 모니터링 응용 프로그램에 따라 다릅니다. 정확한 데이터를 어떻게 전송합니까?

2.I는 데이터 전송 로컬 LAN에서 파일 전송을 제외 할 필요는 때라도 방법은 인터넷 데이터 전송 + 로컬 파일 전송

Option Explicit 

Public Enum OperationalStates 
    MIB_IF_OPER_STATUS_NON_OPERATIONAL = 0 
    MIB_IF_OPER_STATUS_UNREACHABLE = 1 
    MIB_IF_OPER_STATUS_DISCONNECTED = 2 
    MIB_IF_OPER_STATUS_CONNECTING = 3 
    MIB_IF_OPER_STATUS_CONNECTED = 4 
    MIB_IF_OPER_STATUS_OPERATIONAL = 5 
End Enum 
Public Enum InterfaceTypes 
    MIB_IF_TYPE_OTHER = 1 
    MIB_IF_TYPE_ETHERNET = 6 
    MIB_IF_TYPE_TOKENRING = 9 
    MIB_IF_TYPE_FDDI = 15 
    MIB_IF_TYPE_PPP = 23 
    MIB_IF_TYPE_LOOPBACK = 24 
    MIB_IF_TYPE_SLIP = 28 
End Enum 

Public Enum AdminStatuses 
    MIB_IF_ADMIN_STATUS_UP = 1 
    MIB_IF_ADMIN_STATUS_DOWN = 2 
    MIB_IF_ADMIN_STATUS_TESTING = 3 
End Enum 

Private Const MAXLEN_IFDESCR   As Integer = 256 
Private Const MAXLEN_PHYSADDR  As Integer = 8 
Private Const MAX_INTERFACE_NAME_LEN As Integer = 256 
Private Const ERROR_NOT_SUPPORTED As Long = 50 
Private Const ERROR_SUCCESS   As Long = 0 

Private Type MIB_IFROW 
    wszName(0 To 511)      As Byte 
    dwIndex         As Long '// index of the interface 
    dwType         As Long '// type of interface 
    dwMtu         As Long '// max transmission unit 
    dwSpeed         As Long '// speed of the interface 
    dwPhysAddrLen       As Long '// length of physical address 
    bPhysAddr(0 To 7)      As Byte '// physical address of adapter 
    dwAdminStatus       As Long '// administrative status 
    dwOperStatus        As Long '// operational status 
    dwLastChange        As Long 
    dwInOctets        As Long  '// octets received 
    dwInUcastPkts       As Long '// unicast packets received 
    dwInNUcastPkts       As Long '// non-unicast packets received 
    dwInDiscards        As Long '// received packets discarded 
    dwInErrors        As Long '// erroneous packets received 
    dwInUnknownProtos      As Long 
    dwOutOctets        As Long  '// octets sent 
    dwOutUcastPkts       As Long '// unicast packets sent 
    dwOutNUcastPkts       As Long '// non-unicast packets sent 
    dwOutDiscards       As Long '// outgoing packets discarded 
    dwOutErrors        As Long '// erroneous packets sent 
    dwOutQLen        As Long '// output queue length 
    dwDescrLen        As Long '// length of bDescr member 
    bDescr(0 To 255)       As Byte '// interface description 
End Type 

Private m_lngBytesReceived As Long 
Private m_lngBytesSent  As Long 

Private Declare Function GetIfTable _ 
      Lib "IPhlpAPI" (ByRef pIfRowTable As Any, _ 
          ByRef pdwSize As Long, _ 
          ByVal bOrder As Long) As Long 

Private Declare Sub CopyMemory _ 
      Lib "kernel32" _ 
      Alias "RtlMoveMemory" (ByRef pDest As Any, _ 
            ByRef pSource As Any, _ 
            ByVal Length As Long) 

Private Declare Function FreeResource Lib "kernel32" (ByVal hResData As Long) As Long 

Public Property Get BytesReceived() As Long 
BytesReceived = m_lngBytesReceived 
End Property 

Public Property Get BytesSent() As Long 
    BytesSent = m_lngBytesSent 
End Property 

Public Function InitInterfaces() As Boolean 
Dim arrBuffer() As Byte 
Dim lngSize  As Long 
Dim lngRetVal As Long 
Dim Name  As String 
Dim lngRows  As Long 
Dim lngRow  As Long 
Dim i   As Integer 
Dim j   As Integer 
Dim IfRowTable As MIB_IFROW 
On Error GoTo err 

lngSize = 0 
m_lngBytesReceived = 0 
m_lngBytesSent = 0 
lngRetVal = GetIfTable(ByVal 0&, lngSize, 0) 

If lngRetVal = ERROR_NOT_SUPPORTED Then 
    Exit Function 
End If 

ReDim arrBuffer(0 To lngSize - 1) As Byte 
lngRetVal = GetIfTable(arrBuffer(0), lngSize, 0) 

If lngRetVal = ERROR_SUCCESS Then 
    CopyMemory lngRows, arrBuffer(0), 4 

    If lngRows >= 1 Then 

     For lngRow = 1 To lngRows 
      CopyMemory IfRowTable, arrBuffer(4 + (lngRow - 1) * Len(IfRowTable)), Len(IfRowTable) 

      For i = 0 To 25 
       Name = Name & Chr(IfRowTable.bDescr(i)) 

       If IfRowTable.bDescr(i) = Chr(0) Then GoTo ok 
      Next 

ok: 

      If Not InStr(1, Name, "loop", vbTextCompare) > 0 Then 

       With IfRowTable 
        m_lngBytesReceived = m_lngBytesReceived + .dwInOctets 
        m_lngBytesSent = m_lngBytesSent + .dwOutOctets 

       End With 'IFROWTABLE 

       'Set IfRowTable = Nothing 
       InitInterfaces = True 
      End If 

      Name = vbNullString 
     Next 

     Erase arrBuffer 
    End If 

End If 

On Error GoTo 0 
Exit Function 

err: 

Call GErrorHandler(err.Number, err.Description, "CIPHelper:InitInterfaces:" & err.Source, True) 
End Function 

Private Sub GetBandwidth() 
Dim c As New CIpHelper, R As Double, s As Double 
Dim r1 As Double, c1 As Double, SendBytes1 As Double, ReceivedBytes1 As Double 

    On Error GoTo errh: 
    c.InitInterfaces 
    If FirstTime Then 
     FirstTime = False 
     SendBytes = Format(c.BytesSent/1024, ".0") 
     ReceivedBytes = Format(c.BytesReceived/1024, ".0") 
     SendBytes1 = c.BytesSent 
     ReceivedBytes1 = c.BytesReceived 
    Else 'FIRSTTIME = FALSE/0 
     R = ((c.BytesReceived/1024) - ReceivedBytes) 
     s = ((c.BytesSent/1024) - SendBytes) 
    End If  


    lblBandwidthUsed = R+s 

    OldR = R 
    OldS = s 
    On Error GoTo 0 
    Exit Sub 
errh: 

    Call GErrorHandler(err.Number, err.Description, "ScreenBlock:GetBandwidth:" & err.Source, True) 
End Sub 

답변

1

1) 1024 바이트 = 1 킬로바이트 1024 킬로바이트 = 1메가바이트 포함 . 다시 말해, KB 수를 1024로 나눕니다.

2) LAN 트래픽을 모니터링하지 않으려는 경우 무선 트래픽을 모니터링하고 싶다고 가정합니다. 일반 솔루션으로는 다소 까다로울 수도 있지만 LAN 카드의 MAC 주소를 알고있는 경우 "bPhysAddr"변수와 같은 계산에서 제외 할 수 있습니다.

할 수 있습니다 명령 줄에서 명령을 실행하는 PC의 MAC 주소를 얻을 : 답장을 보내

ipconfig /all 
+0

감사합니다, 1) 이미 내가 그 계산을했지만 불을 지르고 내 응용 프로그램과 데이터 전송과 비교하면 2) 동일한 어댑터를 사용하는 무선 장치가 둘 다 설치되지 않았습니다 (인터넷 및 LAN 파일 전송). –

+0

로컬 LAN 컴퓨터 또는 IP가 192.168. *. *로 변환되는 방식을 보면서 인터넷에서 들어오는 패킷을 구별하는 것이 어려울 것이라고 생각합니다. 그러나 게이트웨이의 IP (192.168.1.1 또는 유사)를 알고있는 경우 발신자 또는 수신자가 게이트웨이 IP를 사용하는지 확인하여 다른 컴퓨터를 무시할 수 있습니다. – Neil

+0

샘플 코드 환영 –

관련 문제