IP Info Icon

IP Info

Release Date: 2011

Language Used:

Objective-C

Software Used:

Xcode

Platforms:

iOS, Windows Phone

About:

IP Info was the first app I made, and helped introduce me to programming. Users can manually type in an IP address, or hit the button to use their device's IP to view information on it. That information includes the class, default subnet mask and binary representation for the address.

The inspiration for this app came from my high school networking class. Among other things, we were tasked with learning to extract various pieces of information from an IP address, the hardest being the binary conversion. This app was made to help alleviate that effort.

IP Info has also served as a sort-of "Hello World" app for me; it is the app I will try to re-create when I am learning to code on a new platform. The app is simple enough such that I can easily recreate the UI, while the backend (particularly the binary conversion) is complex enough that it forces me to learn how to do new things on that platform. For exactly this reason, it is my first multi-platform app, supporting both iOS and Windows Phone.

Code Samples

IP Parsing

This code parses the input IP address and extracts each octet for binary conversion.
- (void)convertToBinary:(NSMutableString *) input {
	//the major chunk of this code extracts each octet of the IP address into it's own variable for processing.
	NSString *intake = input;
	
	NSRange decimalLocationOne;
	NSRange decimalLocationTwo;
	NSRange decimalLocationThree;
	
	NSString *firstOctet;
	NSString *secondOctet;
	NSString *thirdOctet;
	NSString *fourthOctet;
	
	decimalLocationOne = [intake rangeOfString: @"."];
	firstOctet = [intake substringToIndex: decimalLocationOne.location];
	intake = [intake substringFromIndex: (decimalLocationOne.location + 1)];
	
	[firstOctetLabel setText: firstOctet];
	
	decimalLocationTwo = [intake rangeOfString: @"."];
	secondOctet = [intake substringToIndex: decimalLocationTwo.location];
	intake = [intake substringFromIndex: (decimalLocationTwo.location + 1)];
	
	[secondOctetLabel setText: secondOctet];
	
	decimalLocationThree = [intake rangeOfString: @"."];
	thirdOctet = [intake substringToIndex: decimalLocationThree.location];
	intake = [intake substringFromIndex: (decimalLocationThree.location + 1)];
	
	[thirdOctetLabel setText: thirdOctet];
	
	fourthOctet = intake;
	
	[fourthOctetLabel setText: fourthOctet];
	
	//once each octet is extracted into it's own variable, each is sent to the real binary converter,
    	//whose results are assigned to the appropriate variable
	NSString *firstOctetBinary = [self binarySubConverter:(NSString *)firstOctet];
	[firstOctetBinaryLabel setText: firstOctetBinary];
	
	NSString *secondOctetBinary = [self binarySubConverter:(NSString *)secondOctet];
	[secondOctetBinaryLabel setText: secondOctetBinary];
	
	NSString *thirdOctetBinary = [self binarySubConverter:(NSString *)thirdOctet];
	[thirdOctetBinaryLabel setText: thirdOctetBinary];
	
	NSString *fourthOctetBinary = [self binarySubConverter:(NSString *)fourthOctet];
	[fourthOctetBinaryLabel setText: fourthOctetBinary];
}

Binary Conversion

This code processes a given octet (as a string) and returns its binary representation. It is limited to processing numbers between 0 and 255, since other numbers were outside the scope of this project.
- (id)binarySubConverter:(NSString *)input {
	NSString *intake = input;
	int intakeInt = [intake intValue];
	NSMutableString *finalBinaryString = [NSMutableString stringWithString: @""];
	
	
	//fixes bug that won't display anything if number is zero
	if (intakeInt == 0) {
		[finalBinaryString appendString: @"00000000"];
		return finalBinaryString;
	} else {
		while (intakeInt!= 0) {
			//try to subtract 128, if the result won't be less than zero.
			if (intakeInt - 128 >= 0) {
				intakeInt = intakeInt - 128;
				[finalBinaryString appendString: @"1"];
			} else {
				[finalBinaryString appendString: @"0"];
			}
			
			
			//try to subtract 64, if the result won't be less than zero
			if (intakeInt - 64 >= 0) {
				intakeInt = intakeInt - 64;
				[finalBinaryString appendString: @"1"];
			} else {
				[finalBinaryString appendString: @"0"];
			}
			
			//try to subtract 32, if the result won't be less than zero
			if (intakeInt - 32 >= 0) {
				intakeInt = intakeInt - 32;
				[finalBinaryString appendString: @"1"];
			} else {
				[finalBinaryString appendString: @"0"];
			}
			
			//getting how this works yet?
			if (intakeInt - 16 >= 0) {
				intakeInt = intakeInt - 16;
				[finalBinaryString appendString: @"1"];
			} else {
				[finalBinaryString appendString: @"0"];
			}
			
			if (intakeInt - 8 >= 0) {
				intakeInt = intakeInt - 8;
				[finalBinaryString appendString: @"1"];
			} else {
				[finalBinaryString appendString: @"0"];
			}
			
			if (intakeInt - 4 >= 0) {
				intakeInt = intakeInt - 4;
				[finalBinaryString appendString: @"1"];
			} else {
				[finalBinaryString appendString: @"0"];
			}
			
			if (intakeInt - 2 >= 0) {
				intakeInt = intakeInt - 2;
				[finalBinaryString appendString: @"1"];
			} else {
				[finalBinaryString appendString: @"0"];
			}
			
			if (intakeInt - 1 >= 0) {
				intakeInt = intakeInt - 1;
				[finalBinaryString appendString: @"1"];
			} else {
				[finalBinaryString appendString: @"0"];
			}
			
			return finalBinaryString;
		}
	}
}