Created
November 14, 2019 11:38
-
-
Save no1xsyzy/11ba23cd13f90b3f94227d4838fd7e5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
;;; Solve <https://www.v2ex.com/t/619370> | |
(define (get-group ipaddr lines) | |
(define group-name null) | |
(let/cc return | |
(map (λ (line) | |
(cond | |
[(parse-group-name line) | |
=> (λ (parsed-group-name) | |
(set! group-name parsed-group-name))] | |
[(equal? (parse-host-name line) ipaddr) | |
(return group-name)])) | |
lines))) | |
(define (parse-group-name line) | |
(if (eq? (car line) 'object-group) | |
(caddr line) | |
#f)) | |
(define (parse-host-name line) | |
(if (eq? (car line) 'network-object) | |
(caddr line) | |
#f)) | |
(define lines | |
'((network-object host 109.17.49.131) | |
(object-group network KaGuan_12) | |
(network-object host 109.17.26.11) | |
(network-object host 109.17.26.12) | |
(object-group network ShangHai) | |
(network-object host 110.1.60.91) | |
(network-object host 110.1.60.92) | |
(network-object host 110.1.172.31) | |
(network-object host 110.1.172.32) | |
(network-object host 110.238.250.57) | |
(network-object host 110.238.250.58) | |
(object-group network wangguan_test) | |
(network-object host 111.17.13.32) | |
(object-group network wangguan_app_2) | |
(network-object host 111.17.9.54) | |
(network-object host 111.17.9.63))) | |
(get-group '110.1.172.32 lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment