<aside> 💡

本文档基于以下版本的软件或包

</aside>

jdk-21
neo4j-community-windows-5.18.0
python==3.12.2
py2neo==2021.2.4
pandas==2.2.1

1 Local

1.2 环境准备

下载JDK21然后配置Java环境变量

下载neo4jGraph Database Self-Managed的community版本

Untitled

而后将neo4j的bin目录加入环境变量。

1.2 启动本地neo4j

启动命令(未将neo4j加入环境变量版)

cd D:\neo4j-community-3.5.20\bin\
.\neo4j.bat console

启动命令(将neo4j加入环境变量版)

neo4j console

1.3 使用Python向本地neo4j写入数据

1.3.1 写入csv数据

from py2neo import Graph, Node, Relationship
import pandas as pd
import csv

# 连接neo4j数据库,输入地址、用户名、密码
graph = Graph('neo4j://localhost:7687', auth=('neo4j', '12345678'))
graph.delete_all()

with open('test.csv', 'r', encoding='utf-8') as f:
    reader = csv.reader(f)
    data = list(reader)

for i in range(1, len(data)):
    # 将下面的绿色的内容换成csv文件里的
    node = Node('name', name=data[i][1], id=data[i][0], level=data[i][7])
    relation = Node('vul_type', name=data[i][2])
    relation1 = Node('cnvd', name=data[i][3])
    relation2 = Node('cnnvd', name=data[i][4])
    relation3 = Node('cve', name=data[i][5])
    graph.create(node)
    graph.create(relation)
    graph.create(relation1)
    graph.create(relation2)
    graph.create(relation3)
		# 这些绿色的是起的关系名
    vul_type = Relationship(node, '漏洞类型', relation)
    cnvd_code = Relationship(node, 'cnvd编码', relation1)
    cnnvd_code = Relationship(node, 'cnnvd编码', relation2)
    cve_code = Relationship(node, 'cve编码', relation3)
    graph.create(vul_type)
    graph.create(cnvd_code)
    graph.create(cnnvd_code)
    graph.create(cve_code)

1.4 本地数据导出dump文件