Giter Site home page Giter Site logo

apollonbar / ldnetdiagnoservice_android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lede-inc/ldnetdiagnoservice_android

0.0 0.0 0.0 7.18 MB

Android平台利用ping和traceroute的原理,对指定域名(通常为后台API的提供域名)进行网络诊断,并收集诊断日志

Java 69.83% Makefile 0.64% C 29.53%

ldnetdiagnoservice_android's Introduction

LDNetDiagnoService_Android

===============

利用ping、tcp connect和traceroute的原理,对指定域名(通常为后台API的提供域名)进行网络诊断,并收集诊断日志。功能通过Service的方式提供给各个产品项目,由各个项目组决定如何使用。

  • Android的实现方案一:

是通过后台线程执行ping命令的方式模拟traceroute的过程,缺点就是模拟过程较慢,timeout的出现比较频繁

  • Android的实现方案二:

通过编译开源网络检测库iputilsC代码的方式对traceroute进行了套接字发送ICMP报文模拟,可以明显提高检测速度;(关于iputils工具原理实现,请参考博文

LDNetDiagnoService最终效果


  • 调用网络诊断服务,监控日志输出;
  • 诊断结束之后,返回日志文本;
  • 调用者可以选择保存、邮件上传、接口上传等方式上传监控日志;

如下图所示:

如何集成LDNetDiagnoService_Android


通过库依赖的方式

  • 拷贝LDNetDiagnoService_Android文件夹到你的代码空间;
  • 在你的主工程中Add LDNetDiagnoService_Android 库工程;

如何使用LDNetDiagnoService_IOS


当service代码集成到工程之后,即可通过如下方式调用网络诊断服务:

  1. Android的service作为一个后台任务,每次开始诊断需要重新初始化一个任务;通过在监控界面设置LDNetDiagnoListener接口的方法监控日志输出;

    • tip:初始化参数只需要初始化appcode,userID, dormain(必须), 其他参数选填;
    public void onClick(View v) {
    if (v == btn) {
      if (!isRunning) {
        showInfo = "";
        String domainName = edit.getText().toString().trim();
        _netDiagnoService = new LDNetDiagnoService(getApplicationContext(),
            "testDemo", "网络诊断应用", "1.0.0", "[email protected]",
            "deviceID(option)", domainName, "carriname", "ISOCountyCode",
            "MobilCountryCode", "MobileNetCode", this);
    
        //设置是否使用JNIC 完成traceroute
        _netDiagnoService.setIfUseJNICTrace(true);
    	//_netDiagnoService.setIfUseJNICConn(true);
        _netDiagnoService.execute();
        ...
      } else {
      	...
        _netDiagnoService.cancel(true);
        _netDiagnoService = null;
        ...
      }
    
      isRunning = !isRunning;
    }
    

} ```

  1. 重载LDNetDiagnoListener方法,监控网络诊断日志;

    • 监控网络诊断过程中的日志输出
    @Override
    public void OnNetDiagnoUpdated(String log) {
    	showInfo += log;
    	text.setText(showInfo);
    }	
    
    • 诊断结束,输出全部日志记录
    @Override
    public void OnNetDiagnoFinished(String log) {
    	progress.setVisibility(View.GONE);
    	btn.setText("开始诊断");
    	_netDiagnoService = null;
    	isRunning = false;
    } 
    
  2. 关于service选择traceroute 方式的说明:默认是支持JNICTrace,如果需要通过ping命令行方式执行,可以通过_netDiagnoService.setIfUseJNICTrace(false)设置;

    ...
    	
    _netDiagnoService = new LDNetDiagnoService();
    
    //设置是否使用JNIC 完成traceroute
    this._netDiagnoService.setIfUseJNICTrace(false);
    
    ...
    

技术支持


to be continued ....

庞辉, 电商技术中心,popo:[email protected]

ldnetdiagnoservice_android's People

Contributors

philonpang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.