mavris / MMLanScan

An iOS LAN Network Scanner library
MIT License
490 stars 121 forks source link

MMLanScan fails to work in Class A network subnet #24

Closed bexp closed 7 years ago

bexp commented 7 years ago

Hi MMLanScan fails to work in Class A network.

my IP/Subnet = 10.231.154.136/255.254.0.0

ipcalc shows 131070 possible hosts in given subnet

Address:   10.231.154.136       00001010.1110011 1.10011010.10001000
Netmask:   255.254.0.0 = 15     11111111.1111111 0.00000000.00000000
Wildcard:  0.1.255.255          00000000.0000000 1.11111111.11111111
=>
Network:   10.230.0.0/15        00001010.1110011 0.00000000.00000000
HostMin:   10.230.0.1           00001010.1110011 0.00000000.00000001
HostMax:   10.231.255.254       00001010.1110011 1.11111111.11111110
Broadcast: 10.231.255.255       00001010.1110011 1.11111111.11111111
Hosts/Net: 131070                Class A, Private Internet

where is NetworkCalculator.getAllHostsForIP calculates this amount to be ~2 million

screen shot 2017-07-10 at 12 27 07 pm

As a result array of IP's allocates ~100Mb of memory and MMLANScanner.start hangs

jpalten commented 7 years ago

I'll look into that right away.

jpalten commented 7 years ago

Writing unit tests for Network Calculator. Seems to be ok though.

jpalten commented 7 years ago

Unit tests work fine. Will create a pull request for the unit tests though.

class NetworkCalculatorTests: XCTestCase {

    func testSubnetSize_classC() {

        let ips = NetworkCalculator.getAllHosts(forIP: "192.168.0.1", andSubnet: "255.255.255.0")
        XCTAssertEqual(ips?.count, 254)
    }

    func testSubnetSize_classB() {

        let ips = NetworkCalculator.getAllHosts(forIP: "192.168.0.1", andSubnet: "255.255.252.0")
        XCTAssertEqual(ips?.count, 1022)
    }

    func testSubnetSize_classA() {

        let ips = NetworkCalculator.getAllHosts(forIP: "10.231.154.136", andSubnet: "255.254.0.0")
        XCTAssertEqual(ips?.count, 131070)
    }

}
jpalten commented 7 years ago

@bexp you are using netmask 255.224.0.0, which is 10.231.154.136/11 which has 2097150 addresses. But you refer to ipcalc with netmask 255.254.0.0 which is 10.231.154.136/15 which has 131070 addresses. So both ipcalc and your code are correct, but using different netmasks.

bexp commented 7 years ago

any idea why the app hangs ? it's handing in your swift example too

mavris commented 7 years ago

I guess 2millions * 2 (ping and mac retrieve) operations are too much to handle. When I was building the framework I was thinking about /24,/23,/22 minimum. I think I will setup some similar network and I will try to optimize it.

bexp commented 7 years ago

I'm on xfinity wifi network (very popular if not the largest internet provided in US) they have hotspots everywhere