Есть довольно простая задача: даны девайсы (радио вышки) у которых из интерфейсов взаимодействия только Telnet, физически. Есть задача снимать с них логи в режиме реального времени, т.е. после ввода определенных команд она начинает выдавать инфу что с ней происходит.
Накатал скриптик на JS, НО почему то вывод "едет" и появляются какие-то левые символы.
Например если снять лог телнетом или nc, то будет примерно следующее:
spoiler[2018/07/26 14:13:24] [tCpeM] CPE[0x8090ede8] carry dns cfg
[2018/07/26 14:13:24] mem is not same, eid[8090ede8]
[2018/07/26 14:13:24] [tCpeM] CPE[0x8090ede8], proflie same=1 , ccb.getProfileInvalidFlag=0
[2018/07/26 14:13:24] [tCpeM] SetVersion[0x7ffe]
[2018/07/26 14:13:24] [tCpeM] post msg to ut ,len:104
[2018/07/26 14:13:24] [tCpeM] send register rsp to CPE[0x8090ede8], with profile.
[2018/07/26 14:13:24] [tCpeM] CPE profile update to CPE[0x8090ede8], transid:0xcf05
[2018/07/26 14:13:24] [tCpeM] Notify tVoice to enable or disable port.
[2018/07/26 14:13:24] [tCpeM] post tDM CPE[0x8090ede8]-config
[2018/07/26 14:13:24] [tCfg] CM_NuclearSendLimitData[UC] eid[8090ede8]
[2018/07/26 14:13:24] [tCpeM]SendValidFreqsParaToCpe cpe[0x8090ede8]
[2018/07/26 14:13:24] [tCpeM]SendCIParaToCpe cpe[0x8090ede8]
[2018/07/26 14:13:24] [tCpeM] CPE[0x8090ede8] register Status[0]. [SERVING]
[2018/07/26 14:13:24] [tCpeM] ->CPE fsm reclaim()
[2018/07/26 14:13:24] [tCpeM] Receive CPE[0x8090ede8] Profile Update Response
[2018/07/26 14:13:24] [tCpeM] CPE[0x8090ede8] register SUCCESS.
[2018/07/26 14:13:24] [tCpeM] CPE_CpeGetNeighborListReq,UT[8090ede8] support V613
[2018/07/26 14:13:24] [tCpeM] eid[8090ede8] version = 3...
[2018/07/26 14:13:24] [tCpeM] CPE_CpeGetNeighborListReqNew,UT[8090ede8] support V613
[2018/07/26 14:13:24] [tCpeM] eid[8090ede8 ]CPE_CpeGetNeighborListReqNew add BtsType NeigBtsNum[0] DataLength = 6...
MCU_SW_version:02.06.00.cf
FPGA_SW_version:02.07.c5.66
MCU_SW_version:02.06.00.cf
FPGA_SW_version:02.07.c5.66
[2018/07/26 14:14:37] [tWRRU] RRU Freq Offset:[a30e],Antenna Mask:[ff] ,Temp:[39],Current:[3]
[2018/07/26 14:14:37] [tWRRU] rru_state_flag:[14]
MCU_SW_version:02.06.00.cf
FPGA_SW_version:02.07.c5.66
MCU_SW_version:02.06.00.cf
FPGA_SW_version:02.07.c5.66
[2018/07/26 14:15:45] [tCpeM] Rx CPE[0x8090edf9] profile update notify.
[2018/07/26 14:15:45] [tCpeM] ->CPE fsm reclaim()
[2018/07/26 14:15:45] [tCpeM] CPE_CpeGetNeighborListReq,UT[8090edf9] support V613
[2018/07/26 14:15:45] [tCpeM] eid[8090edf9] version = 3...
[2018/07/26 14:15:45] [tCpeM] CPE_CpeGetNeighborListReqNew,UT[8090edf9] support V613
[2018/07/26 14:15:45] [tCpeM] eid[8090edf9 ]CPE_CpeGetNeighborListReqNew add BtsType NeigBtsNum[0] DataLength = 6...
MCU_SW_version:02.06.00.cf
FPGA_SW_version:02.07.c5.66
[2018/07/26 14:15:59] [tCpeM] Rx CPE[0x8090ee02] profile update notify.
[2018/07/26 14:15:59] [tCpeM] ->CPE fsm reclaim()
[2018/07/26 14:16:10] [tCpeM] Rx CPE[0x80039b06] profile update notify.
[2018/07/26 14:16:10] [tCpeM] ->CPEServingCpeProfileUpdateNotifyTrans, receive new cpe profile update notify from L2, then send utTable1 to L2
[2018/07/26 14:16:10] [tCpeM] Post ut ability req msg to L2 success
[2018/07/26 14:16:10] [tCpeM] ->CPE fsm reclaim()
А вот что выдает JS:
spoiler[
2018/07/26 14:45:57] [tCpeM] Rx CPE[0x80909bf1] Register_Req, [Serving state],transID:0x27
[2018/07/26 14:45:57] [tCpeM]CPE[0x80909BF1] judge wcpe or rcpe.
[2018/07/26 14:45:57] [tCpeM] CPE[0x80909bf1] profile is valid.
[2018/07/26 14:45:57] [tCpeM] Old cpe register req don't carry utTable1
[2018/07/26 14:45:57] [tCpeM] CPE[0x80909bf1] RegisterReq UT NonAdjacent is [0]
[2018/07/26 14:45:57] [tCpeM] Send CPE[0x80909BF1] BWInfo_Req to HLR.
[2018/07/26 14:45:57] [tCpeM] ->CPE fsm reclaim()
[2018/07/26 14:45:57] [tCpeM] Receive CPE[0x80909bf1] BWInfo_Rsp, Admin_status: 0. [SERVING state]
[2018/07/26 14:45:57] [tCpeM] CPE[0x80909bf1] register Status[0]. [SERVING],BW:8,8
[2018/07/26 14:45:57] [tCpeM] CPE[0x80909bf1] carry dns cfg
[2018/07/26 14:45:57] mem is not same, eid[80909bf1]
[2018/07/26 14:45:57] [tCpeM] CPE[0x80909bf1], proflie same=1 , ccb.getProfileInvalidFlag=0
[2018/07/26 14:45:57] [tCpeM] SetVersion[0x7ffe]
[2018/07/26 14:45:57] [tCpeM] post msg to ut ,len:104
[2018/07/26 14:45:57] [tCpeM] send register rsp to CPE[0x80909bf1], with profile.
[2018/07/26 14:45:57] [tCpeM] CPE profile update to CPE[0x80909bf1], transid:0xcf5a
[2018/07/26 14:45:57] [tCpeM] Notify tVoice to enable or disable port.
[2018/07/26 14:45:57] [tCpeM] post tDM CPE[0x80909bf1]-config
[2018/07/26 14:45:57] [tCfg] CM_NuclearSendLimitData[UC] eid[80909bf1]
[2018/07/26 14:45:57] [tCpeM]SendValidFreqsParaToCpe cpe[0x80909bf1]
[2018/07/26 14:45
:57] [tCpeM]SendCIParaToCpe cpe[0x80909bf1]
[2018/07/26 14:45:57] [tCpeM] CPE[0x80909bf1] register Status[0]. [SERVING]
[2018/07/26 14:45:57] [tCpeM] ->CPE fsm reclaim()
[2018/07/26 14:45:57] [tCpeM] Receive CPE[0x80909bf1] Profile Update Response
[2018/07/26 14:45:57] [tCpeM] CPE[0x80909bf1] register SUCCESS.
[
2018/07/26 14:46:04] [tCpeM] Rx CPE[0x8090edf6] profile update notify.
[2018/07/26 14:46:04] [tCpeM] ->CPE fsm reclaim()
[2018/07/26 14:46:04] [tCpeM] CPE_CpeGetNeighborListReq,UT[8090edf6] support V613
[2018/07/26 14:46:04] [tCpeM] eid[8090edf6] version = 3...
[2018/07/26 14:46:04] [tCpeM] CPE_CpeGetNeighborListReqNew,UT[8090edf6] support V613
[2018/07/26 14:46:04] [tCpeM] eid[8090edf6 ]CPE_CpeGetNeighborListReqNew add BtsType NeigBtsNum[0] DataLength = 6...
[2018/07/26 14:46:04] [tCpeM] Rx CPE[0x8090edf6] Register_Req, [Serving state],transID:0x5
[2018/07/26 14:46:04] [tCpeM]CPE[0x8090EDF6] judge wcpe or rcpe.
[2018/07/26 14:46:04] [tCpeM] CPE[0x8090edf6] profile is valid.
[2018/07/26 14:46:04] [tCpeM] Old cpe register req don't carry utTable1
[2018/07/26 14:46:04] [tCpeM] CPE[0x8090edf6] RegisterReq UT NonAdjacent is [0]
[2018/07/26 14:46:04] [tCpeM] Send CPE[0x8090EDF6] BWInfo_Req to HLR.
[2018/07/26 14:46:04] [tCpeM] ->CPE fsm reclaim()
[2018/07/26 14:46:04] [tCpeM] Receive CPE[0x8090edf6] BWInfo_Rsp, Admin_status: 0. [SERVING state]
[2
018/07/26 14:46:04] [tCpeM] CPE[0x8090edf6] register Status[0]. [SERVING],BW:8,8
[2018/07/26 14:46:04] [tCpeM] CPE[0x8090edf6] carry dns cfg
[2018/07/26 14:46:04] mem is not same, eid[8090edf6]
[2018/07/26 14:46:04] [tCpeM] CPE[0x8090edf6], proflie same=1 , ccb.getProfileInvalidFlag=0
[2018/07/26 14:46:04] [tCpeM] SetVersion[0x7ffe]
[2018/07/26 14:46:04] [tCpeM] post msg to ut ,len:104
[2018/07/26 14:46:04] [tCpeM] send register rsp to CPE[0x8090edf6], with profile.
[2018/07/26 14:46:04] [tCpeM] CPE profile update to CPE[0x8090edf6], transid:0xcf5c
[2018/07/26 14:46:04] [tCpeM] Notify tVoice to enable or disable port.
[2018/07/26 14:46:04] [tCpeM] post tDM CPE[0x8090edf6]-config
[2018/07/26 14:46:04] [tCfg] CM_NuclearSendLimitData[UC] eid[8090edf6]
[2018/07/26 14:46:04] [tCpeM]SendValidFreqsParaToCpe cpe[0x8090edf6]
[2018/07/26 14:46:04] [tCpeM]SendCIParaToCpe cpe[0x8090edf6]
[2018/07/26 14:46:04] [tCpeM] CPE[0x8090edf6] register Status[0]. [SERVING]
[2018/07/26 14:46:04] [tCpeM] ->CPE fsm reclaim()
[2018/07/26 14:46:04] [tCpeM] Receive CPE[0x8090edf6] Profile Update Response
[2018/07/26 14:46:04] [tCpeM] CPE[0x8090edf6] register SUCCESS.
[
2018/07/26 14:46:04] [tCpeM] CPE_CpeGetNeighborListReq,UT[8090edf6] support V613
[2018/07/26 14:46:04] [tCpeM] eid[8090edf6] version = 3...
[2018/07/26 14:46:04] [tCpeM] CPE_CpeGetNeighborListReqNew,UT[8090edf6] support V613
[2018/07/26 14:46:04] [tCpeM] eid[8090edf6 ]CPE_CpeGetNeighborListReqNew add BtsType NeigBtsNum[0] DataLength = 6...
MCU_SW_version:
02.06.00.cf
FPGA_SW_version:02.07.c5.66
Видно что появились какие-то левые переводы строк. Но, казалось бы что для наглядности я взял пример из nc и netcat из npm. Отсюда у меня складывается ощущение что я как-то неправильно обрабатываю buffer.
Первый листинг сделан из
nc. Второй на основнании библиотеки
netcat. Т.е. по факту это должно быть одно и тоже, но нет!
Код:
const NetcatClient = require("netcat/client");
const client = new NetcatClient();
client
.addr("192.168.10.10")
.port(23)
.connect();
client.on("connect", () => {
console.log("Connected!");
});
client.on("data", data => {
console.log(data.toString());
data = data.toString().split(/\r\n/gm);
data.forEach(value => {
switch (value.trim()) {
case "VxWorks login:":
client.send("bts\n");
break;
case "Password:":
client.send("12345678\n");
break;
case "->":
// Основное приглашение
client.send("reDirect 0\n");
break;
default:
// console.log(data);
break;
}
});
});