Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
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
sheteng
com.ccwangluo.accelerator
Commits
26b68530
Commit
26b68530
authored
Jun 18, 2017
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add local DNS to dns list. #1281
parent
a84070c2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
4 deletions
+86
-4
mobile/src/main/java/com/github/shadowsocks/utils/Dns.java
mobile/src/main/java/com/github/shadowsocks/utils/Dns.java
+73
-0
mobile/src/main/scala/com/github/shadowsocks/BaseService.scala
...e/src/main/scala/com/github/shadowsocks/BaseService.scala
+13
-4
No files found.
mobile/src/main/java/com/github/shadowsocks/utils/Dns.java
0 → 100644
View file @
26b68530
/*
* Copyright 2010 Brave New Software Project, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.github.shadowsocks.utils
;
import
android.annotation.SuppressLint
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.annotation.TargetApi
;
import
android.util.Log
;
import
android.net.ConnectivityManager
;
import
android.net.LinkProperties
;
import
android.os.Build
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.net.InetAddress
;
public
class
Dns
{
public
static
String
getDnsResolver
(
Context
context
)
throws
Exception
{
Collection
<
InetAddress
>
dnsResolvers
=
getDnsResolvers
(
context
);
if
(
dnsResolvers
.
isEmpty
())
{
throw
new
Exception
(
"Couldn't find an active DNS resolver"
);
}
String
dnsResolver
=
dnsResolvers
.
iterator
().
next
().
toString
();
if
(
dnsResolver
.
startsWith
(
"/"
))
{
dnsResolver
=
dnsResolver
.
substring
(
1
);
}
return
dnsResolver
;
}
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
private
static
Collection
<
InetAddress
>
getDnsResolvers
(
Context
context
)
throws
Exception
{
ArrayList
<
InetAddress
>
addresses
=
new
ArrayList
<
InetAddress
>();
ConnectivityManager
connectivityManager
=
(
ConnectivityManager
)
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
Class
<?>
LinkPropertiesClass
=
Class
.
forName
(
"android.net.LinkProperties"
);
Method
getActiveLinkPropertiesMethod
=
ConnectivityManager
.
class
.
getMethod
(
"getActiveLinkProperties"
,
new
Class
[]{});
Object
linkProperties
=
getActiveLinkPropertiesMethod
.
invoke
(
connectivityManager
);
if
(
linkProperties
!=
null
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
Method
getDnsesMethod
=
LinkPropertiesClass
.
getMethod
(
"getDnses"
,
new
Class
[]{});
Collection
<?>
dnses
=
(
Collection
<?>)
getDnsesMethod
.
invoke
(
linkProperties
);
for
(
Object
dns
:
dnses
)
{
addresses
.
add
((
InetAddress
)
dns
);
}
}
else
{
for
(
InetAddress
dns
:
((
LinkProperties
)
linkProperties
).
getDnsServers
())
{
addresses
.
add
(
dns
);
}
}
}
return
addresses
;
}
}
mobile/src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
26b68530
...
@@ -341,12 +341,21 @@ trait BaseService extends Service {
...
@@ -341,12 +341,21 @@ trait BaseService extends Service {
val
remoteDns
=
new
JSONArray
(
profile
.
remoteDns
.
split
(
","
).
zipWithIndex
.
map
{
val
remoteDns
=
new
JSONArray
(
profile
.
remoteDns
.
split
(
","
).
zipWithIndex
.
map
{
case
(
dns
,
i
)
=>
makeDns
(
"UserDef-"
+
i
,
dns
.
trim
)
case
(
dns
,
i
)
=>
makeDns
(
"UserDef-"
+
i
,
dns
.
trim
)
})
})
profile
.
route
match
{
val
localDns
=
new
JSONArray
(
Array
(
case
Acl
.
BYPASS_CHN
|
Acl
.
BYPASS_LAN_CHN
|
Acl
.
GFWLIST
|
Acl
.
CUSTOM_RULES
=>
config
.
put
(
"PrimaryDNS"
,
new
JSONArray
(
Array
(
makeDns
(
"Primary-1"
,
"119.29.29.29"
,
edns
=
false
),
makeDns
(
"Primary-1"
,
"119.29.29.29"
,
edns
=
false
),
makeDns
(
"Primary-2"
,
"114.114.114.114"
,
edns
=
false
)
makeDns
(
"Primary-2"
,
"114.114.114.114"
,
edns
=
false
)
)))
))
try
{
val
localLinkDns
=
com
.
github
.
shadowsocks
.
utils
.
Dns
.
getDnsResolver
(
this
)
localDns
.
put
(
makeDns
(
"Primary-3"
,
localLinkDns
,
edns
=
false
))
}
catch
{
case
_:
Exception
=>
// Ignore
}
profile
.
route
match
{
case
Acl
.
BYPASS_CHN
|
Acl
.
BYPASS_LAN_CHN
|
Acl
.
GFWLIST
|
Acl
.
CUSTOM_RULES
=>
config
.
put
(
"PrimaryDNS"
,
localDns
)
.
put
(
"AlternativeDNS"
,
remoteDns
)
.
put
(
"AlternativeDNS"
,
remoteDns
)
.
put
(
"IPNetworkFile"
,
"china_ip_list.txt"
)
.
put
(
"IPNetworkFile"
,
"china_ip_list.txt"
)
.
put
(
"DomainFile"
,
"gfwlist.txt"
)
.
put
(
"DomainFile"
,
"gfwlist.txt"
)
...
...
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