|
| C++ Reconnect | |
| | Author | Message |
---|
Maccaz Forum Mod
Posts : 870 Join date : 2009-04-23 Location : Adelaide, Australia
| Subject: C++ Reconnect Sat 01 Aug 2009, 03:07 | |
| Well I got a friend to make this for me, as he is fluent in C++. Usually I had to go through my webbrowser, go to my ip address, type in the user and password, click restart and then submit, Now it bypasses all that without even having to open a browser. It uses httpwinsock and the live http headers I collected by going to the webpage that actually restarts my modem. If anyone understands this, they can probably change it to their own modem if they need to restart it the same way as me. - Code:
-
#include <WinSock2.h> #include <Windows.h> #include <iostream> #include <tchar.h> #include <strsafe.h>
void ShowErrAndExit(PTSTR lpszFunction) { LPVOID lpMsgBuf; LPVOID lpDisplayBuf; DWORD dw = GetLastError();
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL );
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR)); StringCchPrintf((LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf) / sizeof(TCHAR), TEXT("%s failed with error %d: %s"), lpszFunction, dw, lpMsgBuf); std::cout << lpDisplayBuf << std::endl;
LocalFree(lpMsgBuf); LocalFree(lpDisplayBuf); ExitProcess(1); }
int _tmain() { // startup network WSADATA wsaData; if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) ShowErrAndExit(TEXT("WSAStartup"));
// create network socket SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (hSocket == INVALID_SOCKET) ShowErrAndExit(TEXT("Socket"));
// connect sockaddr_in modem; modem.sin_family = AF_INET; modem.sin_port=htons(80); modem.sin_addr.s_addr = inet_addr("192.168.1.254"); if (connect(hSocket, (sockaddr*) &modem, sizeof(sockaddr_in)) == SOCKET_ERROR) ShowErrAndExit(TEXT("Connect"));
// send reboot string char* lpData = "GET /doc/doreboot.htm HTTP/1.1\r\nHost: 192.168.1.254\r\nConnection: keep-alive\r\nAuthorization: Basic YWRtaW46cGFzc3dvcmQ=\r\n\r\n"; if (send(hSocket, lpData, (int) strlen(lpData) + 1, NULL) == SOCKET_ERROR) ShowErrAndExit(TEXT("Send"));
// cleanup closesocket(hSocket);
bool reboot = false; do { // wait 50 seconds for (int x = 0; x < 50; x++) Sleep (1000);
// check for connect twice if (gethostbyname("www.google.com") == NULL && gethostbyname("www.yahoo.com") == NULL) { Sleep(10000); if (gethostbyname("www.google.com") == NULL && gethostbyname("www.yahoo.com") == NULL) reboot = true; else reboot = false; } else reboot = false;
// connection still not established, reboot modem if (reboot == true) { hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
modem.sin_family = AF_INET; modem.sin_port=htons(80); modem.sin_addr.s_addr = inet_addr("192.168.1.254"); if (connect(hSocket, (sockaddr*) &modem, sizeof(sockaddr_in)) == SOCKET_ERROR) ShowErrAndExit(TEXT("Connect"));
if (send(hSocket, lpData, (int) strlen(lpData) + 1, NULL) == SOCKET_ERROR) ShowErrAndExit(TEXT("Send"));
closesocket(hSocket); } } while (reboot != false); // while reboot = true
// cleanup WSACleanup(); return 0; }
| |
| | | Yaboirobby * * * * * * * * * * *
Posts : 4322 Join date : 2009-05-21 Age : 29 Location : Atlanta, GA
| Subject: Re: C++ Reconnect Sat 01 Aug 2009, 03:17 | |
| Sorry for the noob question, but what is this? What is C++ Reconnect? | |
| | | Maccaz Forum Mod
Posts : 870 Join date : 2009-04-23 Location : Adelaide, Australia
| Subject: Re: C++ Reconnect Sat 01 Aug 2009, 04:20 | |
| C++ is a programming language and that is what my reconnect is programmed in :) | |
| | | Bruzaholman * * * * * * * * *
Posts : 796 Join date : 2009-06-01 Age : 31 Location : England
| Subject: Re: C++ Reconnect Sat 01 Aug 2009, 08:18 | |
| | |
| | | Maccaz Forum Mod
Posts : 870 Join date : 2009-04-23 Location : Adelaide, Australia
| Subject: Re: C++ Reconnect Sat 01 Aug 2009, 08:28 | |
| - Bruzaholman wrote:
- What modem do you have?
Quite an old one, Billion BIPAC-7100 Pro | |
| | | w13winni VIP
Posts : 282 Join date : 2009-04-17
| Subject: Re: C++ Reconnect Sat 01 Aug 2009, 10:50 | |
| yes this prog send a request ( get or post) for reboot the box i create a php script for that coupled with a .bat just fetch the request on tamperdata for exemple | |
| | | Maccaz Forum Mod
Posts : 870 Join date : 2009-04-23 Location : Adelaide, Australia
| Subject: Re: C++ Reconnect Sat 01 Aug 2009, 10:59 | |
| - w13winni wrote:
- yes this prog send a request ( get or post) for reboot the box
i create a php script for that coupled with a .bat just fetch the request on tamperdata for exemple Yea it sends a GET request with the correct http headers and authorization and reboots it :) Then checks after 50 seconds if internet is working again, and again after another 10 seconds it checks, and if not it will run the reboot again. It does not need to POST any data, I had to find out all the info before hand - which took only a little while. | |
| | | BobTheBear admin
Posts : 4102 Join date : 2009-05-15 Location : Scotland!
| Subject: Re: C++ Reconnect Sat 01 Aug 2009, 12:50 | |
| Nice!
Your friend is clearly a handy person to know! | |
| | | Maccaz Forum Mod
Posts : 870 Join date : 2009-04-23 Location : Adelaide, Australia
| Subject: Re: C++ Reconnect Sat 01 Aug 2009, 12:51 | |
| - BobTheBear wrote:
- Nice!
Your friend is clearly a handy person to know! I know basics of things, but he knows practically everything, he even knows ASM (assembler) | |
| | | w13winni VIP
Posts : 282 Join date : 2009-04-17
| Subject: Re: C++ Reconnect Sat 01 Aug 2009, 13:07 | |
| - TraehDliw09 wrote:
It does not need to POST any data,
yes,you are lucky^^ but on the almost all box, we must send a postdata for reboot box i creat .bat/php for 6 frenchs box and all need a postdata request for reboot the box but its works :) - TraehDliw09 wrote:
he even knows ASM (assembler) ho great, this langage is very hard | |
| | | Maccaz Forum Mod
Posts : 870 Join date : 2009-04-23 Location : Adelaide, Australia
| | | | Sponsored content
| Subject: Re: C++ Reconnect | |
| |
| | | | C++ Reconnect | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| |