use shields-up instead of our own port checker
This commit is contained in:
parent
e6b61665f3
commit
08e5372e56
Binary file not shown.
|
@ -29,6 +29,7 @@ typedef enum
|
||||||
PORT_STATUS_CHECKING,
|
PORT_STATUS_CHECKING,
|
||||||
PORT_STATUS_OPEN,
|
PORT_STATUS_OPEN,
|
||||||
PORT_STATUS_CLOSED,
|
PORT_STATUS_CLOSED,
|
||||||
|
PORT_STATUS_STEALTH,
|
||||||
PORT_STATUS_ERROR
|
PORT_STATUS_ERROR
|
||||||
} port_status_t;
|
} port_status_t;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#import "PortChecker.h"
|
#import "PortChecker.h"
|
||||||
#import "NSApplicationAdditions.h"
|
#import "NSApplicationAdditions.h"
|
||||||
|
|
||||||
#define CHECKER_URL @"http://www.transmissionbt.com/PortCheck.php?port=%d"
|
#define CHECKER_URL @"https://www.grc.com/x/portprobe=%d"
|
||||||
#define CHECK_FIRE 3.0
|
#define CHECK_FIRE 3.0
|
||||||
|
|
||||||
@implementation PortChecker
|
@implementation PortChecker
|
||||||
|
@ -114,18 +114,49 @@
|
||||||
|
|
||||||
- (void) connectionDidFinishLoading: (NSURLConnection *) connection
|
- (void) connectionDidFinishLoading: (NSURLConnection *) connection
|
||||||
{
|
{
|
||||||
NSString * probeString = [[NSString alloc] initWithData: fPortProbeData encoding: NSASCIIStringEncoding];
|
NSXMLDocument * shieldsUpProbe = [[NSXMLDocument alloc] initWithData: fPortProbeData options: NSXMLDocumentTidyHTML error: nil];
|
||||||
|
[fPortProbeData release];
|
||||||
|
fPortProbeData = nil;
|
||||||
|
|
||||||
port_status_t status;
|
if (shieldsUpProbe)
|
||||||
if ([probeString isEqualToString: @"1"])
|
{
|
||||||
status = PORT_STATUS_OPEN;
|
NSArray * nodes = [shieldsUpProbe nodesForXPath: @"/html/body/center/table[3]/tr/td[2]" error: nil];
|
||||||
else if ([probeString isEqualToString: @"0"])
|
if ([nodes count] != 1)
|
||||||
status = PORT_STATUS_CLOSED;
|
{
|
||||||
|
NSArray * title = [shieldsUpProbe nodesForXPath: @"/html/head/title" error: nil];
|
||||||
|
// This may happen when we probe twice too quickly
|
||||||
|
if ([title count] != 1 || ![[[title objectAtIndex: 0] stringValue] isEqualToString:
|
||||||
|
@"NanoProbe System Already In Use"])
|
||||||
|
{
|
||||||
|
NSLog(@"Unable to get port status: invalid (outdated) XPath expression");
|
||||||
|
[[shieldsUpProbe XMLData] writeToFile: @"/tmp/shieldsUpProbe.html" atomically: YES];
|
||||||
|
[self callBackWithStatus: PORT_STATUS_ERROR];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSString * portStatus = [[[[nodes objectAtIndex: 0] stringValue] stringByTrimmingCharactersInSet:
|
||||||
|
[[NSCharacterSet letterCharacterSet] invertedSet]] lowercaseString];
|
||||||
|
|
||||||
|
if ([portStatus isEqualToString: @"open"])
|
||||||
|
[self callBackWithStatus: PORT_STATUS_OPEN];
|
||||||
|
else if ([portStatus isEqualToString: @"stealth"])
|
||||||
|
[self callBackWithStatus: PORT_STATUS_STEALTH];
|
||||||
|
else if ([portStatus isEqualToString: @"closed"])
|
||||||
|
[self callBackWithStatus: PORT_STATUS_CLOSED];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSLog(@"Unable to get port status: unknown port state");
|
||||||
|
[self callBackWithStatus: PORT_STATUS_ERROR];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[shieldsUpProbe release];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
status = PORT_STATUS_ERROR;
|
{
|
||||||
|
NSLog(@"Unable to get port status: failed to create xml document");
|
||||||
[probeString release];
|
[self callBackWithStatus: PORT_STATUS_ERROR];
|
||||||
[self callBackWithStatus: status];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -272,6 +272,10 @@
|
||||||
[fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Advanced -> port status")];
|
[fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Advanced -> port status")];
|
||||||
[fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.png"]];
|
[fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.png"]];
|
||||||
break;
|
break;
|
||||||
|
case PORT_STATUS_STEALTH:
|
||||||
|
[fPortStatusField setStringValue: NSLocalizedString(@"Port is stealth", "Preferences -> Advanced -> port status")];
|
||||||
|
[fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.png"]];
|
||||||
|
break;
|
||||||
case PORT_STATUS_ERROR:
|
case PORT_STATUS_ERROR:
|
||||||
[fPortStatusField setStringValue: NSLocalizedString(@"Unable to check port status",
|
[fPortStatusField setStringValue: NSLocalizedString(@"Unable to check port status",
|
||||||
"Preferences -> Advanced -> port status")];
|
"Preferences -> Advanced -> port status")];
|
||||||
|
|
Loading…
Reference in New Issue