# 去重指令 distinct = ''' match (n:NodeResolver53) WITH n ORDER BY n.W DESC with n.IP as IP,collect(n) as nodes,count(*) as c where c>1 CALL apoc.refactor.mergeNodes(nodes, {properties:'discard',mergeRels:true}) YIELD node RETURN count(*) ''' # 新建catelog gds_newgraph = ''' CALL gds.graph.project( 'myGraph', 'NodeResolver53', 'IP_LINK', { relationshipProperties: 'W' } ) ''' # 删除旧的catelog gds_delgraph = ''' CALL gds.graph.drop('myGraph', false) YIELD graphName ''' # 高风险节点 dangerous_nodes = ''' CALL gds.pageRank.stream('myGraph') YIELD nodeId, score with gds.util.asNode(nodeId) as n WHERE n.IPType contains "6" RETURN n.IP as ip, n.ISP as isp,n.CCODE as ccode,n.COU as cou,n.PROV as prov, n.LAT as lat,n.LNG as lng ,score ORDER BY score DESC limit %s''' # 高危节点邻居 dnode_neighbor = ''' CALL gds.pageRank.stream('myGraph') YIELD nodeId, score WHERE gds.util.asNode(nodeId).IPType contains "6" with gds.util.asNode(nodeId) AS no, score ORDER BY score DESC limit %s with collect(no) as nlist MATCH (m:NodeResolver53)-[r:IP_LINK]->(n:NodeResolver53) WHERE n in nlist and m.IPType contains "4" RETURN n.IP,r.W,m''' # 节点邻居 node_neighbors = '''MATCH(n:NodeResolver53{IP:'%s'})-[]->(m:NodeResolver53) RETURN m''' # 节点全部信息 # IP关联数据,以地理位置代表 IP_relate = '''MATCH (n:NodeResolver53)-[]->(m:NodeResolver53) with n.LAT as flat,n.LNG as flng,m.LAT as tlat,m.LNG as tlng ,count(*) as c RETURN flat,flng,tlat,tlng,c order by c DESC limit 10000 ''' # AS关联数据 AS_relate = ''' MATCH(n:NodeResolver53)-[l:IP_LINK]->(d:NodeResolver53) WITH n.AS AS fasn, d.AS AS tasn, count(*) AS c RETURN fasn,tasn,c order by c DESC limit 10000 ''' # ISP关联数据 ISP_relate = '''MATCH(n:NodeResolver53)-[l:IP_LINK]->(d:NodeResolver53) WITH n.ISP AS fisp, d.ISP AS tisp, count(*) AS c RETURN fisp,tisp,c order by c DESC limit 10000''' # AS分布 AS_dist = '''MATCH(n:NodeResolver53{IPType:"v6"}) with n.AS as asn,count(*) as c RETURN asn,c order by c DESC limit 10000 ''' # ISP分布统计 ISP_dist = '''MATCH(n:NodeResolver53{IPType:"v6"}) with n.ISP as isp,count(*) as c RETURN isp,c order by c DESC limit 10000 ''' # 国家分布统计 cou_dist = '''MATCH(n:NodeResolver53{IPType:"v6"}) with n.COU as cou,count(*) as c RETURN cou,c''' ccode_dist = '''MATCH(n:NodeResolver53{IPType:"v6"}) with n.CCODE as ccode,count(*) as c RETURN ccode,c''' # 双栈服务数量统计 dualcountcypher = ''' CALL gds.wcc.stream('myGraph') YIELD nodeId,componentId with componentId as cid,count(*) as c where 1