summaryrefslogtreecommitdiff
path: root/script/neo4jcommand.py
blob: 0aa8cddcf18c445706b4a42f544d6e234f93f821 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 去重指令
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, score  
ORDER BY score DESC, ip ASC,isp ASC,ccode ASC,cou ASC,prov ASC limit 30'''


# 节点邻居
node_neighbors=''''''



# IP关联数据
IP_relate=''''''


# AS关联数据
AS_relate=''''''


# ISP关联数据
ISP_relate=''''''


# 所有节点信息
all_node=''''''


# AS分布
AS_dist=''''''


# ISP分布统计
ISP_dist=''''''

# 国家分布统计
cou_dist=''''''






# 双栈服务数量统计
dualcountcypher = '''
   CALL gds.wcc.stream('myGraph')
   YIELD nodeId,componentId
   with componentId as cid,count(*) as c
   where 1<c<4
   with collect(cid) as cc
   CALL gds.wcc.stream('myGraph')
   YIELD nodeId,componentId
   where componentId in cc
   with gds.util.asNode(nodeId).IP as ip,componentId
   where ip contains ":"
   return count(distinct componentId)
   '''

# 双栈服务详细数据
dualdatacypher = '''
   CALL gds.wcc.stream('myGraph')
   YIELD nodeId,componentId
   with componentId as cid,count(*) as c
   where 1<c<4
   with collect(cid) as cc
   CALL gds.wcc.stream('myGraph')
   YIELD nodeId,componentId
   where componentId in cc
   with gds.util.asNode(nodeId).IP as ip,componentId
   where ip contains ":"
   with  collect(componentId) as ccl
   CALL gds.wcc.stream('myGraph')
   YIELD nodeId,componentId
   where componentId in ccl
   with gds.util.asNode(nodeId) as n,componentId
   return n.IP,n.ISP,n.COU,n.CCODE,n.PROV,n.LAT,n.LNG,componentId 
   order by componentId limit 30
   '''

# v6dns计数
v6count = '''
match (n:NodeResolver53) where n.IPType contains "6" return count(n)'''

delQuery = '''
CALL apoc.periodic.commit("MATCH (n:NodeResolverQuery) WITH n LIMIT $limit DETACH DELETE n RETURN count(*)",{limit: 10000})
YIELD updates, executions, runtime, batches 
RETURN updates, executions, runtime, batches;'''