Documents & code‎ > ‎

DIG Response A/AAAA/NS/MX/TXT/SOA (In::VB.NET)

DIG Response A/AAAA/NS/MX/TXT/SOA (In::VB.NET)   
post id92 
post length5526 
post datetime6/5/2012 8:30:09 PM 
post ip10.10.10.254 

DIG Response A/AAAA/NS/MX/TXT/SOA (In::VB.NET)


I`t Insert in body of previous example 
        urlhttp://pesap.com/code.aspx?pid=91 


For simpl`y, did not use bit shift operator`s. Used BitConverter 


            '... 

            Dim ofs As Integer _ 
                    = 12 + [Question].Data.Length 
            Dim LI, FI As Integer 
            For As Integer = ofs To Data.Length - 1 
                If (Data(i) = 192) Or (i = Data.Length - 1) Then 
                    FI = LI _ 
                             : LI = i 
                    If Not FI = 0 Then 
                        Dim I_RDLENGTH As Int16 _ 
                                = BitConverter.ToInt16({Data(FI + 11), Data(FI + 10)}, 0) 
                        i = i + (FI + 12 + I_RDLENGTH - LI) : LI = i 
                        Dim As UShort _ 
                                = BitConverter.ToUInt16(Data, FI + 1) 
                        Dim [NAME] As String _ 
                                = READ_STRING(Data, T) 
                        Dim [TYPE] As Int16 _ 
                                = BitConverter.ToInt16({Data(FI + 3), Data(FI + 2)}, 0) _ 
                          , [CLASS] As Int16 _ 
                                = BitConverter.ToInt16({Data(FI + 5), Data(FI + 4)}, 0) _ 
                          , RDATA As String = Nothing 
                        Select Case [TYPE] 
                            Case QType.A 
                                RDATA = IPAddress.Parse(String.Concat(Data(FI + 12) _ 
                                                               , ".", Data(FI + 13) _ 
                                                               , ".", Data(FI + 14) _ 
                                                               , ".", Data(FI + 15))).ToString 
                            Case QType.AAAA 
                                Dim Address As IPAddress = Nothing 
                                IPAddress.TryParse(String.Format("{0:x}:{1:x}:{2:x}:{3:x}:{4:x}:{5:x}:{6:x}:{7:x}" _ 
                                                        , New Object() {BitConverter.ToInt16({Data(FI + 13), Data(FI + 12)}, 0), _ 
                                                                        BitConverter.ToInt16({Data(FI + 15), Data(FI + 14)}, 0), _ 
                                                                        BitConverter.ToInt16({Data(FI + 17), Data(FI + 16)}, 0), _ 
                                                                        BitConverter.ToInt16({Data(FI + 19), Data(FI + 18)}, 0), _ 
                                                                        BitConverter.ToInt16({Data(FI + 21), Data(FI + 20)}, 0), _ 
                                                                        BitConverter.ToInt16({Data(FI + 23), Data(FI + 22)}, 0), _ 
                                                                        BitConverter.ToInt16({Data(FI + 25), Data(FI + 24)}, 0), _ 
                                                                        BitConverter.ToInt16({Data(FI + 27), Data(FI + 26)}, 0)}), Address) 
                                RDATA = Address.ToString 
                            Case QType.NS, QType.MX, QType.TXT, QType.SOA 
                                RDATA = READ_STRING(Data, FI + 12) 
                        End Select 
                        Console.Write(String.Concat([NAME], vbTab, I_PARSE_ENUM(GetType(QType), [TYPE]) _ 
                                                          , vbTab, I_PARSE_ENUM(GetType(QClass), [CLASS]) _ 
                                                          , vbTab, I_RDLENGTH _ 
                                                          , vbTab, RDATA, vbCrLf)) 
                    End If 
                End If 
            Next 
            '... 


MORE: 


    #Region " UTIL`S " 

    Public Function READ_STRING(ByVal Data As Byte(), ByVal ofs As Integer) As String 
        Try 
            Dim str As String = Nothing 
            For As Integer = ofs + 1 To Data.Length - 1 
                Dim ch As Char _ 
                        = Encoding.ASCII.GetChars(Data, i, 1)(0) 
                If Data(i) = 0 Then 
                    Exit For 
                ElseIf Data(i) = 192 Then 
                    Dim _str As String = READ_STRING(Data, Data(i + 1)) 
                    str = String.Concat(str, ".", _str) 
                    i += 2 
                    Exit For 
                Else 
                    If Char.IsControl(ch) Then 
                        ch = "."c 
                    End If 
                End If 
                '... 
                '... 
                str = String.Concat(str, ch) 
            Next 
            Return str 
        Catch ex As Exception 
            Return Nothing 
        End Try 
    End Function 

    Public Function I_PARSE_ENUM(ByVal enumType As Type, ByVal Value As Integer) As String 
        Dim ret As String = Nothing 
        For Each As FieldInfo In enumType.GetFields() 
            Dim _T As Integer = CInt(0) 
            Try 
                _T = _T Or DirectCast(Convert.ChangeType(T.GetValue(Nothing), GetType(Integer), Nothing), Integer) 
                If _T = Value Then 
                    ret = T.Name _ 
                        : Exit For 
                End If 
            Catch ex As Exception 
            End Try 
        Next 
        Return ret 
    End Function 

    #End Region 

Comments