use shields-up instead of our own port checker

This commit is contained in:
Mitchell Livingston 2007-12-31 02:17:27 +00:00
parent e6b61665f3
commit 08e5372e56
4 changed files with 47 additions and 11 deletions

View File

@ -29,6 +29,7 @@ typedef enum
PORT_STATUS_CHECKING,
PORT_STATUS_OPEN,
PORT_STATUS_CLOSED,
PORT_STATUS_STEALTH,
PORT_STATUS_ERROR
} port_status_t;

View File

@ -25,7 +25,7 @@
#import "PortChecker.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
@implementation PortChecker
@ -114,18 +114,49 @@
- (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 ([probeString isEqualToString: @"1"])
status = PORT_STATUS_OPEN;
else if ([probeString isEqualToString: @"0"])
status = PORT_STATUS_CLOSED;
if (shieldsUpProbe)
{
NSArray * nodes = [shieldsUpProbe nodesForXPath: @"/html/body/center/table[3]/tr/td[2]" error: nil];
if ([nodes count] != 1)
{
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
status = PORT_STATUS_ERROR;
[probeString release];
[self callBackWithStatus: status];
{
NSLog(@"Unable to get port status: failed to create xml document");
[self callBackWithStatus: PORT_STATUS_ERROR];
}
}
@end

View File

@ -272,6 +272,10 @@
[fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Advanced -> port status")];
[fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.png"]];
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:
[fPortStatusField setStringValue: NSLocalizedString(@"Unable to check port status",
"Preferences -> Advanced -> port status")];