Thanks Travis,  I'm surprised; there is a lot I have to learn when it
comes to IP matching to CIDR
I was under the impression that just looking at the beginning of CIDR
address and I would be able to find the match.  How wrong I was :-/

Now, I can install * dev-lang/clojure  on Linux
How do I run that code you gave me from the command line?
I suppose I need to put it into a file, now which part?

Thanks,
Joseph

On Wed, Feb 10, 2021 at 9:33 PM Travis Rodman <trod...@apple.com.invalid> wrote:
>
> Hi Syscon,
>
> Okay, so I wrote up a little program to parse your .htaccess file, and this 
> comes back as a match:
> 212.129.0.0/1
>
> Here is the code (Clojure), so you can parse any future mystery rejections, 
> if you like.
> ----------------------------------------------------------------------------------------------------------------------------------------------------
> (ns htaccess.core)
>
> (defn parse-ip [s]
>   (let [v (clojure.string/split s #"/")]
>     (flatten
>       (if (< (count v) 2)
>         [(clojure.string/split (get v 0) #"\.") "32"]
>         [(clojure.string/split (get v 0) #"\.") (get v 1)]))))
>
> (defn convert-str-to-binary-str [s]
>   (clojure.string/replace (format "%0$8s" (java.lang.Integer/toBinaryString 
> (java.lang.Integer/parseUnsignedInt (clojure.string/trim s)))) " " "0"))
>
> (defn convert-mask-to-binary-str [s]
>   (let [m (java.lang.Integer/parseUnsignedInt (clojure.string/trim s))
>         m (if (< 32 m) 32 m)
>         l0 (repeatedly m (fn [] 1))
>         l1 (repeatedly (- 32 m) (fn [] 0))
>         v  (apply str (flatten [l0 l1]))]
>     v))
>
> (defn binary-string-to-int [s] (java.lang.Integer/parseUnsignedInt 
> (clojure.string/trim s) 2))
>
> (defn masked? [p m]
>   (let [s0  p
>         s1  m
>         p0  (parse-ip s0)
>         p1  (parse-ip s1)
>         v0  (apply str (map convert-str-to-binary-str (take 4 p0)))
>         v1  (apply str (map convert-str-to-binary-str (take 4 p1)))
>         m   (convert-mask-to-binary-str (last p1))
>         im  (binary-string-to-int m)
>         iv0 (binary-string-to-int v0)
>         iv1 (binary-string-to-int v1)]
>     (= (bit-and im iv0) (bit-and im iv1))))
>
> (defn get-mask-data [s]
>   (map (fn [s] (clojure.string/replace s "Require not ip " ""))
>     (filter (fn [s] (clojure.string/includes? s "Require not ip "))
>       (with-open [rdr (clojure.java.io/reader s)]
>         (doall (line-seq rdr))))))
>
> (defn return-matching-blocks [p f] (filter (fn [a] (masked? p a)) 
> (get-mask-data f)))
>
> ;(return-matching-blocks "1.202.0.0" 
> "/Users/travis/data/projects/clojure/htaccess/resources/htaccess_backup")
> ;(return-matching-blocks "159.14.184.11" 
> "/Users/travis/data/projects/clojure/htaccess/resources/htaccess_backup")
> ;("212.129.0.0/1")
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
> If you have other IPs that are a mystery, and don't know how to set up 
> Clojure, you can just send them my way, I can easily re-run this. I'm not
> going to chuck the code any time soon.
>
> HTH,
> Travis
>
>
> On Wed, Feb 10, 2021 at 05:25:27PM -0800, Travis Rodman wrote:
> > Thanks, I got it... I will get back to you.
> >
> > Regards,
> > Travis
> >
> > On Wed, Feb 10, 2021 at 06:02:45PM -0700, syscon edm wrote:
> > > Thank you, I sent you the .htaccess file to the email address you 
> > > provided.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscr...@community.apache.org
> > For additional commands, e-mail: dev-h...@community.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@community.apache.org
> For additional commands, e-mail: dev-h...@community.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@community.apache.org
For additional commands, e-mail: dev-h...@community.apache.org

Reply via email to