如何通过以太网连接设备时设置DNS?

时间:2018-05-09 08:54:28

标签: android networking dns resolver ndc

我的android目标是使用静态IP通过以太网连接。 我可以使用ADB连接它,但我无法ping任何服务器。 请告诉我如何配置我的DNS设置,以便我可以ping任何服务器。

2 个答案:

答案 0 :(得分:3)

超级用户使用此命令

<强>苏

适用于marshmallow 6.x之前的版本

ndc resolver setifdns(interface)(dns1)(dns2)

例如 - ndc resolver setifdns eth0 8.8.8.8 8.8.4.4

来自marshmallow 6.x

的版本的

ndc resolver setnetdns(interface)(dns1)(dns2)

例如 - ndc resolver setnetdns eth0 8.8.8.8 8.8.4.4

答案 1 :(得分:-2)

Android 8.0

///////////////////////////////////////////////// ////////////

import json
import sys
import os.path

def main(argv):

    #Load JSON
    current_folder = os.path.dirname(os.path.realpath(__file__))
    with open(current_folder + '\\input.json') as json_file:  
        data = json.load(json_file)

    #Flatten (using for loops)
    flat=[]
    for entry in data['row']:
        for column in entry['column']:
            flat.append(column['text'])

    # OR, Flatten the pythonic way (using list comprehension)
    # looks strange at first but notice
    #   1. we start with the item we want to keep in the list
    #   2. the loops order is the same, we just write them inline 
    flat2 = [ column['text'] for entry in data['row'] for column in entry['column'] ]


    #Format data for saving to JSON
    output = {}
    output['@index']=data['@index']
    output['row'] = flat #or flat2 

    #Save to JSON
    with open('flat.txt', 'w') as outfile:
        json.dump(output, outfile, indent=4)

if __name__ == "__main__":
   main(sys.argv[1:])

///////////////////////////////////////////////// ///////////