Created
June 10, 2012 19:08
-
-
Save erran/2906954 to your computer and use it in GitHub Desktop.
Shodan Generate IP List Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Shodan Generate IP List Example | |
// Generation of an "IP List" using the Objective-C Shodan API | |
// | |
// main.m | |
// shodan_ips | |
// | |
// Created by Erran Carey on 6/10/12. | |
// Copyright (c) 2012 App2O. All rights reserved. | |
// | |
#import "shodan_ips.h" | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSLog(@"Welcome to the Objective-C SHODAN API."); | |
NSLog(@"Generating a list of IP Addresses."); | |
//Initialize the shodan_ips object. | |
shodan_ips* ipgen = [[[shodan_ips alloc]init]autorelease]; | |
/*Prompt for a query and save the IP addresses to ipgen.ip_list*/ | |
[ipgen generate_ip_list]; | |
/*Print the IP Addresses*/ | |
NSLog(@"%@",ipgen.ip_list); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// shodan_ips.h | |
// shodan | |
// | |
// Created by Erran Carey on 6/2/12. | |
// Copyright (c) 2012 @ipwnstuff. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import "shodan.h" | |
@interface shodan_ips : NSObject | |
@property (strong,nonatomic) NSMutableArray* ip_list; | |
-(void)generate_ip_list; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// api.m | |
// shodan | |
// | |
// Created by Erran Carey on 6/2/12. | |
// Copyright (c) 2012 @ipwnstuff. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import "shodan_ips.h" | |
@implementation shodan_ips | |
@synthesize ip_list; | |
-(void)generate_ip_list{ | |
//Configuration | |
char apichar[50] = {0}; | |
printf("Enter your API key: "); | |
scanf("%s", apichar); | |
NSString* api_key = [NSString stringWithUTF8String:apichar]; | |
//Initialize an WebAPI object with your developer api key | |
WebAPI* api = [[[WebAPI alloc]init_with_api_key:api_key]autorelease]; | |
//Perform the search. | |
char querychar[50] = {0}; | |
printf("Enter your query: "); | |
scanf("%s", querychar); | |
NSString* query = [NSString stringWithUTF8String:querychar]; | |
NSDictionary* result = [api search:query]; | |
self.ip_list = [NSMutableArray arrayWithCapacity:[[result objectForKey:@"matches"] count]]; | |
//Loop through matches, print each IP address, and fill the 'ip_list'. | |
int i = 0; | |
for (NSDictionary* host in [result objectForKey:@"matches"]) { | |
host = [[result objectForKey:@"matches"] objectAtIndex:i]; | |
[self.ip_list addObject:[host objectForKey:@"ip"]]; | |
i++; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment