NetworkPackets.Dns.DnsPacket.IPMemBlockToString C# (CSharp) Method

IPMemBlockToString() public static method

Takes in an IP Address in dns format and returns a string. The format is abcd (byte[] {a, b, c, d}.
public static IPMemBlockToString ( MemBlock ip ) : String
ip MemBlock a memblock containing abcd.
return String
    public static String IPMemBlockToString(MemBlock ip) {
      if(ip.Length != 4 && ip.Length != 6) {
        throw new Exception("Invalid IP");
      }
      String res = ip[0].ToString();
      for(int i = 1; i < ip.Length; i++) {
        res += "." + ip[i].ToString();
      }
      return res;
    }

Usage Example

Exemplo n.º 1
0
        /**
         * <summary>Creates a response given the entire packet.</summary>
         * <remarks>The entire packet must be given, because some name servers take
         * advantage of pointers to reduce their size.</remarks>
         * <param name="Data">The entire Dns packet.</param>
         * <param name="Start">The starting position of the Response.</param>
         */
        public Response(MemBlock Data, int Start)
        {
            int idx = 0;

            NameBlob = DnsPacket.RetrieveBlob(Data, Start, out idx);

            int type = (Data[idx++] << 8) + Data[idx++];

            Type = (DnsPacket.Types)type;

            CacheFlush = ((Data[idx] & 0x80) == 0x80) ? true : false;
            int rclass = ((Data[idx++] << 8) & 0x7F) + Data[idx++];

            Class = (DnsPacket.Classes)rclass;

            Ttl  = (Data[idx++] << 24);
            Ttl |= (Data[idx++] << 16);
            Ttl |= (Data[idx++] << 8);
            Ttl |= (Data[idx++]);

            RdLength  = (short)((Data[idx++] << 8) + Data[idx++]);
            RDataBlob = Data.Slice(idx, RdLength);

            if (Type == DnsPacket.Types.Ptr)
            {
                try {
                    Name = DnsPacket.PtrMemBlockToString(NameBlob);
                }
                catch {
                    Name = DnsPacket.HostnameMemBlockToString(NameBlob);
                }
                int End = 0;
                RDataBlob = DnsPacket.RetrieveBlob(Data, idx, out End);
                RData     = DnsPacket.HostnameMemBlockToString(RDataBlob);
            }
            else if (Type == DnsPacket.Types.A)
            {
                Name  = DnsPacket.HostnameMemBlockToString(NameBlob);
                RData = DnsPacket.IPMemBlockToString(RDataBlob);
            }
            _icpacket = _packet = Data.Slice(Start, idx + RdLength - Start);
        }
All Usage Examples Of NetworkPackets.Dns.DnsPacket::IPMemBlockToString