Exemple #1
0
        unsafe public void Run(string text, Action <ip_t> detectedIpAction)
        {
            var ct      = CharTypeEnum.Whitespace; //for text who's start with ip-address
            var prev_ct = default(CharTypeEnum);

            fixed(char *_base = text)
            {
                for (var ptr = _base; ; ptr++)
                {
                    prev_ct = ct;
                    ct      = _CHARTYPE_MAP[*ptr];
                    //first number
                    if (!ct.IsNumber())
                    {
                        if (ct.IsEOS())
                        {
                            break;
                        }
                        continue;
                    }

                    //previous char may be WhiteSpace or Punctuation
                    if (!prev_ct.IsWhitespacePunctuation())
                    {
                        continue;
                    }

                    //first octet
                    var len = TryRecogizeIpFirstOctet(ptr);
                    if (len < 0)
                    {
                        continue;
                    }
                    var startPtr = ptr;
                    ptr += len;

                    //second octet
                    len = TryRecogizeIpOctet(ptr);
                    if (len < 0)
                    {
                        goto SKIP_FEW_CHARS;
                    }
                    ptr += len;

                    //three octet
                    len = TryRecogizeIpOctet(ptr);
                    if (len < 0)
                    {
                        goto SKIP_FEW_CHARS;
                    }
                    ptr += len;

                    //four octet
                    len = TryRecogizeIpLastOctet(ptr);
                    if (len < 0)
                    {
                        goto SKIP_FEW_CHARS;
                    }
                    ptr += len;

                    var ip = new ip_t()
                    {
                        startIndex = (int)(startPtr - _base),
                        length     = (int)(ptr - startPtr),
                    #if DEBUG
                        value = new string( startPtr, 0, (int)(ptr - startPtr)),
                    #endif
                    };
                    detectedIpAction(ip);
                    ptr--;
                    continue;

SKIP_FEW_CHARS:
                    if (_CHARTYPE_MAP[*ptr].IsEOS())
                    {
                        break;
                    }
                }
            }
        }
Exemple #2
0
 private void AddIpToList(ip_t ip)
 {
     _Ips.Add(ip);
 }