Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
Hey all,

I'm trying to create a simple telnet application for my iPhone and iPad.
This will stay simple and just gather 'show port-security' from cisco switches.
And after that I will throw results in a tableview and unlock them by pressing the cells. However I can't login.

Code:
- (void)viewDidLoad {
    [super viewDidLoad];

    [self initNetworkCommunication];
}

- (void) initNetworkCommunication {
    CFReadStreamRef readStream;
    CFWriteStreamRef writeStream;
    CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"IP TO MY SWITCH HERE", 23, &readStream, &writeStream);
	
    inputStream = (NSInputStream *)readStream;
    outputStream = (NSOutputStream *)writeStream;
    [inputStream setDelegate:self];
    [outputStream setDelegate:self];
    [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [inputStream open];
    [outputStream open];
}

- (IBAction) sendMessage {
    NSString *myInput  = [NSString stringWithFormat:@"%@", sendString.text];
    NSData *data = [[NSData alloc] initWithData:[myInput dataUsingEncoding: NSUTF8StringEncoding]];
    [outputStream write:[data bytes] maxLength:[data length]];
    sendString.text = @"";
}


- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
	NSLog(@"Received streamEvent: %i", streamEvent);
	switch (streamEvent) {
		case NSStreamEventOpenCompleted:
			NSLog(@"Stream opened..");
			break;
		case NSStreamEventHasBytesAvailable:
            if (theStream == inputStream) {
				uint8_t buffer[1024];
				int len;
				while ([inputStream hasBytesAvailable]) {
					len = [inputStream read:buffer maxLength:sizeof(buffer)];
					if (len > 0) {
						NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSUTF8StringEncoding];
						if (nil != output)
							NSLog(@"Reply: %@", output);
					}
				}
			}
			break;
		case NSStreamEventErrorOccurred:
			NSLog(@"Can not connect to the host!");
			break;
		case NSStreamEventEndEncountered:
            NSLog(@"End event encountered?");
            [theStream close];
            [theStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
            [theStream release];
            theStream = nil;
			break;
		default:
			NSLog(@"Unknown event");
	}
}


It does connect fine: Log:
Code:
.........
User Access Verification

Username:

However when I'm sending my username through the text field. The reply will be the username I'm sending to it.
Then it should be asking my password, what it doesn't.
Looks like, or the 'enter' key is not sended or the session dies ? (Also when I type my username\n) It will send the \n as text so thats not really helpfull)
Because after sending my password, it will say End event encounterd..

Is there anyone having any experience with these kind of telnet sessions ? Because I could use some help here.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.