1

I need to check if some ports (8888 and 8889) are open in a private network (196.168.xxx.xxx).

I have tried to bind the port, but I always get the same result either if the port is open or not (I have 2 networks with different configurations for testing)

GCDAsyncUdpSocket *_udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSError *error = nil;
BOOL b = [_udpSocket bindToPort:8888 error:&error]

I've also tried this code from here:

size_t len = 0;
if (sysctlbyname("net.inet.tcp.pcblist_n", 0, &len, 0, 0) < 0) {
    perror("sysctlbyname");
} else {
    char *buf = malloc(len);
    sysctlbyname("net.inet.tcp.pcblist_n", buf, &len, 0, 0);
    NSData *data = [NSData dataWithBytesNoCopy:buf length:len];
    NSLog(@"data = %@", data);
}

But I don't know how to work with the response.

Any idea? I think the problem is that I'm not sure about what I'm looking for.

Thanks!

Community
  • 1
  • 1
Ale
  • 2,282
  • 5
  • 38
  • 67
  • 1
    Binding alone won't help you - that makes your app listen on that port on the local device - which you will always be able to (unless some other app as already bound to that port). To find out if the socket is open you need to send a message to some known host on the required port and have that host send a reply. – Paulw11 Sep 11 '15 at 10:30

0 Answers0