Giter Club home page Giter Club logo

mediaios / net-diagnosis Goto Github PK

View Code? Open in Web Editor NEW
549.0 9.0 131.0 2.49 MB

ios平台网络诊断SDK,支持对ip和域名的ping,traceroute(udp,icmp协议),支持tcp ping, 端口扫描,nslookup,局域网活跃ip扫描等功能-----------Ios platform network diagnostic SDK, support ip and domain name ping, traceroute (udp, icmp protocol), support tcp ping, port scan, nslookup, LAN active ip scan and other functions

License: MIT License

C 1.68% Objective-C 62.18% Objective-C++ 30.66% Ruby 4.60% C++ 0.88%

net-diagnosis's Introduction

iOS network diagnostics sdk

Introduction

By ingegrating iOS network diagnostics sdk you can easily do ping/traceroute/mobile public network information/port scanning on IPhone.

Take a screenshot of the network diagnostic app developed with this sdk:

图片说明图片说明 图片说明
图片说明图片说明 图片说明
图片说明图片说明图片说明

Environment

  • iOS >= 9.0
  • Xcode >= 7.0
  • Setting Enable Bitcode to NO

Installation and use

Pod dependency

Add the following dependencies to your project's Podfile:

pod 'PhoneNetSDK'

Quick start

Import the SDK header file to the project:

#import <PhoneNetSDK/PhoneNetSDK.h>

In addition, you need to add -lc++,-ObjC,$(inherited) to the project's Build Setting->other link flags. As shown below:

ping

 [[PhoneNetManager shareInstance] netStartPing:@"www.baidu.com" packetCount:10 pingResultHandler:^(NSString * _Nullable pingres) {
       // your processing logic 
  }];

TCP ping

_tcpPing = [PNTcpPing start:hostDomain port:portNum.integerValue count:3 complete:^(NSMutableString *pingres) {
	// your processing logic
}];

UDP traceroute

The default traceroute command on the command line sends a UDP packet (referred to as udp traceroute):

 _udpTraceroute = [PNUdpTraceroute start:ip complete:^(NSMutableString *res) {
                    // your processinig logic
                }];

ICMP traceroute

In the terminal of mac, enter traceroute -I baidu.com to use the ICMP protocol to do traceroute. This function is provided in sdk:

 [[PhoneNetManager shareInstance] netStartTraceroute:@"www.baidu.com" tracerouteResultHandler:^(NSString * _Nullable tracertRes, NSString * _Nullable destIp) {
     // your processing logic                
  }];

nslookup

[[PhoneNetManager shareInstance] netLookupDomain:@"www.google.com" completeHandler:^(NSMutableArray<DomainLookUpRes *> * _Nullable lookupRes, PNError * _Nullable sdkError) {
	// your processing logic
}];

port scan

[[PhoneNetManager shareInstance] netPortScan:@"www.baidu.com" beginPort:8000 endPort:9000 completeHandler:^(NSString * _Nullable port, BOOL isOpen, PNError * _Nullable sdkError) {
	// your processing logic    
}];

LAN Scanning

If you want to do the LAN active ip scanning function, then you can quickly monitor every active ip with the SDK, and the SDK will return to you the scanning progress.

Specific steps are as follows:

  1. Create an object and set the proxy PNetMLanScannerDelegate
  2. Start the scan and process the active ip through its delegate method
  3. Monitor scan progress (optional)
 PNetMLanScanner *lanScanner = [PNetMLanScanner shareInstance];
 lanScanner.delegate =  self;
 [lanScanner scan];

Ohter functions

  • Setting SDK log level
  • Get device public ip info

NetPinger-Example

Ios platform network diagnostic APP (using the SDK), support ping and domain name ping, traceroute (udp, icmp protocol), support tcp ping, port scan, nslookup and other functions.

Simply go to the directory where the Podfile file is located and install the SDK to run successfully.

macdeiMac:NetPinger ethan$ pod install 
Analyzing dependencies
Downloading dependencies
Installing PhoneNetSDK (1.0.7)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `NetPinger.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

Project origin

In development, you often encounter problems with the interface (DNS resolution error, etc.), so you need to detect whether the mobile terminal to the server's network is not connected, so you need to interrupt ping on the mobile phone, but the free network detection tool on the market. Most have pop-up ads affecting the experience (eg: iNetTools), so it is necessary to develop a web drama detection app.

Implementation

All functions are implemented using the functions provided by the SDK. The pages and icons are mainly imitating the NetWork Utility on the MAC, and hope to provide a valuable reference for your application.

Contact us

  • If you have any questions or need any feature, please submit issue
  • If you want to contribute, please submit pull request
  • Welcome star & fork

net-diagnosis's People

Contributors

mediaios avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

net-diagnosis's Issues

建议增加特定端口扫描

因为要对扫描出来的ip进行特定端口扫描,比如80/8080/10230/这种,端口相隔较远,如果按照目前您提供的方法,只能从0开始进行扫描,很耗时,不知可否添加一个根据数组内的端口号进行扫描的方法,谢谢!

Wi-Fi诊断(如频段、信道)是否能获取

大佬,有以下疑惑:

  1. 是否能获取当前Wi-Fi的 频段、信道等的信息
  2. 是否可以获取周围Wi-Fi的频段、信道等信息(以列表形式展示)

大概类似apple自己推出的airport应用

PNTcpPing在处理一个连接不上的IP的时候,超时时间不能设定

- (int)connect:(struct sockaddr_in *)addr{
    int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (sock == -1) {
        return errno;
    }
    int on = 1;
    setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on));
    setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&on, sizeof(on));
    
    struct timeval timeout;
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
    setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout));
    if (connect(sock, (struct sockaddr *)addr, sizeof(struct sockaddr)) < 0) {
        int err = errno;
        close(sock);
        return err;
    }
    close(sock);
    return 0;
}

我设置了timeout后还是不能,要等好久

icmp ping 时的疑问

  1. ping结束时对socket的操作
    只调用了shutdown,没有调用close
  2. 在ping时调用了两次settingUHostSocketAddressWithHost
    这样就会生成两次socket
  3. 域名解析做了两次
    settingUHostSocketAddressWithHost和convertDomainToIp

多线程同时ping很多域名的时候有可能会crash

每次ping一个域名,phonePingServise会实例化一个PhonePing对象,然后PhonePing会执行gethostbyname这个阻塞的方法,当这时候又ping了一个域名,之前那个phonePing就被释放了,然后当他继续执行gethostbyname之后的逻辑的时候,会发现self已经被dealloc了,产生野指针错误

netStopPing not work

continue loop in -sendAndrecevPingPacket after call the -netStopPing.
this cause leak.

How can i detect when traceroute finished?

PhoneNetManager.shareInstance().netStartTraceroute("google.com") { (tracertRes, desIp) in
print("###########* (tracertRes!)")
}

Started traceroute, but now how can i notify when this task finished ?

tcping功能异常

例如:
我设置了重复10次,但是如果在第n次connect失败,那么就不会执行剩下的10-n次了。

那这样的话计算failed次数就没有意义了,因为一旦有一个failed后面的都不会再执行。

我看其他语言实现的tcping都是可以断掉之后继续的,像这样:

success 10ms
success 11ms
failed
success 9ms
failed
success 12ms

finish test, total 6 times, success 4 times, failed 2 times.

但是目前该程序实现的是这样:

success 10ms
failed
然后就停了。。

这种情况常见于去连接一个国外延迟不稳定的IP

目前看下来问题主要是出在这里:

    sigset(SIGALRM, tcp_conn_handler);
    alarm(1);
    int conn_res = connect(self->sock, (struct sockaddr *)addr, sizeof(struct sockaddr));
    alarm(0);
    sigrelse(SIGALRM);

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.