Telnet over a socket with GCDAsyncSocket

戏子无情 提交于 2019-12-01 17:26:50

So a big problem came from the fact that the prompts (login: or password:) do no end the line with CR NL (0D:0A). And I was doing

[self.socket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:0];

so I was never reading the data that held the prompt (a big problem also was that wireshark wasnt working (fixed that myself too)). Once I figured this out I changed the line above to:

[self.socket readDataWithTimeout:-1 tag:0];

Which successfully gave me my prompt. Below are the negotiations Im sending to get to this point and what the original questions entailed (same as above in the update):

will terminal type - 0xFF, 0xFB, 0x18

will negotiate about window size - 0xFF, 0xFB, 0x1F

wont terminal speed - 0xFF, 0xFC, 0x20

wont X display location - 0xFF, 0xFC, 0x23

will new environment option - 0xFF, 0xFB, 0x27

Suboptions

 negotiate about window size - 0xFF, 0xFA, 0x1F, 0x00, 0x50, 0x00, 0x19
 end - 0xFF, 0xF0

 new enviroment option - 0xFF,0xFA, 0x27, 0x00, 
 end - 0xFF, 0xF0

 Terminal Type (ANSI) -  0xFF,0xFA, 0x18, 0x00, 0x41, 0x4E, 0x53, 0x49, 
 end - 0xFF, 0xF0

do suppress go ahead - 0xFF, 0xFD, 0x03

will echo - 0xFF, 0xFB, 0x01

dont status - 0xFF, 0xFE, 0x05

wont remote flow control - 0xFF,0xFC, 0x21

wont echo - 0xFF, 0xFC, 0x01

Do echo - 0xFF,0xFD, 0x01

This might also help. It removes the negotiation bytes from the stream so when your encoding to make the string it doesnt include negotiation bytes.

while([[self.networkBuffer objectAtIndex:0]isEqualToString:@"FF"])
    {
        if ([[self.networkBuffer objectAtIndex:1]isEqualToString:@"FD"] || [[self.networkBuffer objectAtIndex:1]isEqualToString:@"FB"] || [[self.networkBuffer objectAtIndex:1]isEqualToString:@"FE"] || [[self.networkBuffer objectAtIndex:1]isEqualToString:@"FA"]) {

            //most negotiation options are 3 bytes long
            int indexToRemoveFromBuffer = 3;

            //if FA then they are longer then 3 bytes
            if ([[self.networkBuffer objectAtIndex:1]isEqualToString:@"FA"]) {
                //look for indicator of END (F0)
                indexToRemoveFromBuffer = [self.networkBuffer indexOfObject:@"F0"]+1;

            }

            //remove these bytes from networkbuffer
            self.networkBuffer = [NSMutableArray arrayWithArray:[self.networkBuffer subarrayWithRange:NSMakeRange(indexToRemoveFromBuffer, [self.networkBuffer count]-indexToRemoveFromBuffer)]];

            if ([self.networkBuffer count] == 0) {
                if (self.isLoggedIn) {
                    [self.socket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:0];//CRLFData
                }else{
                    [self.socket readDataWithTimeout:-1 tag:0];
                }
                return;
            }
        }else{
            break;
        }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!