Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tun
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
tun
Commits
62aef8a2
Commit
62aef8a2
authored
Mar 16, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix domain resolve duplicate
parent
fd9d712a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
9 deletions
+31
-9
package.json
package.json
+2
-3
process.sh
process.sh
+0
-1
src/inventory.ts
src/inventory.ts
+29
-5
No files found.
package.json
View file @
62aef8a2
...
...
@@ -3,9 +3,8 @@
"version"
:
"1.0.0"
,
"description"
:
""
,
"scripts"
:
{
"build"
:
"tsc"
,
"start"
:
"node build/inventory.js"
,
"all"
:
"npm run build && npm start"
"start"
:
"ts-node src/inventory.ts"
,
"all"
:
"npm start"
},
"dependencies"
:
{
"
@types/ip
"
:
"
^1.1.0
"
,
...
...
process.sh
View file @
62aef8a2
...
...
@@ -12,7 +12,6 @@ set -e
#cd ..
mkdir
-p
result
npm run build
npm start
...
...
src/inventory.ts
View file @
62aef8a2
...
...
@@ -74,10 +74,10 @@ class InventoryBuilder {
}
}
async
resolveDomain
(
domain
:
string
,
ipv6
:
boolean
)
{
if
(
!
domain
||
domain
.
match
(
/
(\d{1,3}\.){3}\d{1,3}
/
))
{
return
domain
;
}
domainResolveFunctions
=
new
Map
<
string
,
((
result
:
string
)
=>
void
)[]
>
();
async
resolveDomainProcess
(
domain
:
string
,
ipv6
:
boolean
)
{
const
cacheKey
=
`
${
domain
}
-
${
ipv6
?
'
:v6
'
:
'
v4
'
}
`
;
if
(
this
.
resolveCache
.
has
(
domain
))
{
return
this
.
resolveCache
.
get
(
domain
);
}
...
...
@@ -99,6 +99,30 @@ class InventoryBuilder {
return
resolvedIP
;
}
async
resolveDomain
(
domain
:
string
,
ipv6
:
boolean
)
{
if
(
!
domain
||
domain
.
match
(
/
(\d{1,3}\.){3}\d{1,3}
/
))
{
return
domain
;
}
return
new
Promise
<
string
>
(
async
(
resolve
)
=>
{
const
cacheKey
=
`
${
domain
}
-
${
ipv6
?
'
:v6
'
:
'
:v4
'
}
`
;
if
(
this
.
resolveCache
.
has
(
cacheKey
))
{
resolve
(
this
.
resolveCache
.
get
(
cacheKey
));
}
else
{
let
resolveFunctions
=
this
.
domainResolveFunctions
.
get
(
cacheKey
);
if
(
!
resolveFunctions
)
{
resolveFunctions
=
[];
this
.
domainResolveFunctions
.
set
(
cacheKey
,
resolveFunctions
);
const
result
=
await
this
.
resolveDomainProcess
(
domain
,
ipv6
);
resolve
(
result
);
resolveFunctions
.
forEach
(
f
=>
f
(
result
));
this
.
domainResolveFunctions
.
delete
(
cacheKey
);
}
else
{
resolveFunctions
.
push
(
resolve
);
}
}
})
}
async
load
(
sheetName
:
string
):
Promise
<
Record
<
string
,
any
>
[]
>
{
const
data
=
await
fs
.
promises
.
readFile
(
path
.
join
(
'
data
'
,
`内网互联计划 -
${
sheetName
}
.csv`
));
// @ts-ignore
...
...
@@ -422,7 +446,7 @@ class InventoryBuilder {
if
(
!
localGateway
.
ipv6
&&
!
remoteGateway
.
ipv4
&&
remoteGateway
.
ipv6
)
{
remoteAddress
=
null
;
}
const
resolvedRemoteAddress
=
remoteAddress
?
await
this
.
resolveDomain
(
remoteAddress
,
!
remoteGateway
.
ipv4
&&
remoteGateway
.
ipv6
)
:
null
;
const
resolvedRemoteAddress
=
remoteAddress
?
await
this
.
resolveDomain
(
remoteAddress
,
(
!
remoteGateway
.
ipv4
||
localGateway
.
ipv6
)
&&
remoteGateway
.
ipv6
)
:
null
;
const
remoteLocalAddress
=
remote
.
address
;
const
remoteNextMark
=
remote
.
nextMark
;
const
remoteDestMark
=
remote
.
destMark
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment