This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
JoeImp
Enlightened


Active Member


Joined: 24 May 2003
Posts: 747

Posted: 31 Dec 2003 11:21:07 am    Post subject:

Well here ya go, I finally picked it up again, I was doing other stuff before. Include ws2_32.lib and it should compile fine under almost any C++ compiler.

If it compiles fine, but if you get 15 "unresolved external symbols" - Include ws2_32.lib!


Code:
#include <iostream.h>
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>

#define SIO_RCVALL _WSAIOW(IOC_VENDOR,1)
int packetscan(char *logfile, int *option);
int processpacket(char *packet, char *logfile, int *option);
void displayip(char *packet, char *logfile, int *option);
void displaytcp(char *packet, char *logfile, int *option);
void displayudp(char *packet, char *logfile, int *option);
void displayicmp(char *packet, char *logfile, int *option);

struct IPHEADER
{
    unsigned char ip_hl:4, ip_v:4;
    unsigned char  ip_tos;
    unsigned short ip_totallength;
    unsigned short ip_id;
    unsigned short ip_offset;
    unsigned char  ip_ttl;
    unsigned char  ip_protocol;
    unsigned short ip_checksum;
    unsigned int   ip_srcaddr;
    unsigned int   ip_destaddr;
};
struct TCPHEADER
{
    unsigned short sport;
    unsigned short dport;
    unsigned int   seqnum;
    unsigned int   acknum;
    unsigned char  DataOffset;
    unsigned char  Flags;
    unsigned short Windows;
    unsigned short Checksum;
    unsigned short UrgPointer;
};
struct UDPHEADER
{
    unsigned short sport;
    unsigned short dport;
    unsigned short Length;
    unsigned short Checksum;
};
struct ICMPHEADER
{
    unsigned char  icmp_type;
    unsigned char  icmp_code;
    unsigned short icmp_cksum;
    unsigned short icmp_id;
    unsigned short icmp_seq;
};

void main()
{
   char command[50];
   char logfile[50] = "none";
   int option[8], errorcode;
   for (int x = 0; x <= 7; x++)
   {option[x] =0;}
   system("CLS");
   cout << "[IceWatch Version 2.0]"
        << "\n[Coded By Joe Impellizzieri]"
        << "\n[WARNING: Coder Not At Fault For Illegal Usage/Damage Sustained]"
        << "\n\nEnter 'clist' For Available Commands\n";
   cout.flush();
   while ((strcmp(command, "scan")) != 0)
   {
  option[6] = 0;
  memcpy(command, " ", sizeof(command));
  cout << "\n> ";
  cin.getline(command, 50);
  if ((strcmp(command, "clist")) == 0)
  {
     option[6] = 1;
     cout << "\n[CLIST - AVAILIBLE COMMANDS]"
          << "\nscan        - Starts The Scan"
          << "\nignoreTCP   - Scan Will Ignore TCP Packets"
          << "\nignoreUDP   - Scan Will Ignore UDP Packets"
          << "\nignoreICMP  - Scan Will Ignore ICMP Packets"
          << "\niponly      - Scan Will Only Display IP Header Info"
          << "\nnoip        - Scan Will Not Display IP Header Info"
          << "\nnodata      - Scan Will Not Display Packet Data"
          << "\nreset       - Resets All Options To Default\n";
  }
  if ((strcmp(command, "ignoreTCP")) == 0)
  {
     option[0] = 1;
     option[6] = 1;
     cout << "[Scan Will Ignore TCP Packets]\n";
  }
  if ((strcmp(command, "ignoreUDP")) == 0)
  {
     option[1] = 1;
     option[6] = 1;
     cout << "[Scan Will Ignore UDP Packets]\n";
  }
  if ((strcmp(command, "ignoreICMP")) == 0)
  {
     option[2] = 1;
     option[6] = 1;
     cout << "[Scan Will Ignore ICMP Packets]\n";
  }
  if ((strcmp(command,"iponly")) == 0)
  {
     option[4] = 0;
     option[3] = 1;
     option[6] = 1;
     cout << "[Scan Will Only Display IP Header Info]\n";
  }
  if ((strcmp(command, "noip")) == 0)
  {
     option[4] = 1;
     option[3] = 0;
     option[6] = 1;
     cout << "[Scan Will Not Display IP Header Info]\n";
  }
  if ((strcmp(command, "nodata")) == 0)
  {
     option[7] = 1;
     option[6] = 1;
     cout << "[Scan Will Not Display Packet Data]\n";
  }
  if ((strcmp(command, "reset")) == 0)
  {
     for (int x = 0; x <= 7; x++)
     {option[x] =0;}
     option[6] = 1;
     cout << "[Options Reset]\n";
  }
  if ((strcmp(command, "scan")) == 0)
     break;
  if (option[6] == 0)
     cout << "Unknown Command\n";
  cout.flush();
   }
   errorcode = packetscan(logfile, option);
   switch (errorcode)
   {
   case 0:
   break;
   }
}

int packetscan(char *logfile, int *option)
{
   WSADATA WsaDat;
   HOSTENT *HostInfo;
   SOCKET rawsock;
   SOCKADDR_IN sockaddr;
   DWORD returned;
   char name[255], buffer[65535];
   unsigned long inbuf;
   if ((WSAStartup(MAKEWORD(2,1), &WsaDat)) != 0)
  return 1;
   rawsock = socket(AF_INET, SOCK_RAW, IPPROTO_IP);
   if (rawsock == INVALID_SOCKET)
  return 2;
   gethostname(name, 255);
   HostInfo = gethostbyname(name);
   sockaddr.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)HostInfo->h_addr_list[0][0];
   sockaddr.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)HostInfo->h_addr_list[0][1];
   sockaddr.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)HostInfo->h_addr_list[0][2];
   sockaddr.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)HostInfo->h_addr_list[0][3];
   sockaddr.sin_family = AF_INET;
   sockaddr.sin_port = htons(6000);
   if (bind(rawsock, (SOCKADDR *)&sockaddr, sizeof(sockaddr)) != 0)
  return 3;
   WSAIoctl(rawsock, SIO_RCVALL, &inbuf, sizeof(inbuf), NULL, 0, &returned, NULL, NULL);
   system("CLS");
   cout << "[Waiting For Packets...]";
   cout.flush();
   while (1)
   {
  memset(buffer, 0, sizeof(buffer));
  recv(rawsock, buffer, sizeof(buffer), 0);
  processpacket(buffer, logfile, option);
  cout.flush();
   }
   return 0;
}

int processpacket(char *packet, char *logfile, int *option)
{
   IPHEADER *ipheader;
   ipheader = (IPHEADER *)packet;
   if ( ((ipheader->ip_protocol == IPPROTO_TCP) && (option[0] == 1)) ||
   ((ipheader->ip_protocol == IPPROTO_UDP) && (option[1] == 1)) ||
    ((ipheader->ip_protocol == IPPROTO_ICMP) && (option[2] == 1)))
   return 1;
   if (option[3] == 1)
   {
  displayip(packet, logfile, option);
  return 1;
   }
   if (option[4] == 0)
  displayip(packet, logfile, option);
   if (ipheader->ip_protocol == IPPROTO_TCP)
  displaytcp(packet, logfile, option);
   if (ipheader->ip_protocol == IPPROTO_UDP)
  displayudp(packet, logfile, option);
   if (ipheader->ip_protocol == IPPROTO_ICMP)
  displayicmp(packet, logfile, option);
   return 1;
}

void displayip(char *packet, char *logfile, int *option)
{
   IPHEADER *ipheader;
   SOCKADDR_IN srcip, dstip;
   char sourceip[30], destip[30];
   ipheader = (IPHEADER *)packet;
   srcip.sin_addr.s_addr = ipheader->ip_srcaddr;
   dstip.sin_addr.s_addr = ipheader->ip_destaddr;
   strcpy(sourceip, inet_ntoa(srcip.sin_addr));
   strcpy(destip, inet_ntoa(dstip.sin_addr));
   cout << "\n\n[**********PACKET**********]"
        << "\n\n[--- IP HEADER ---]"
        << "\n[" << sourceip << " -> " << destip << "]"
        << "\n[Version: " << (int)ipheader->ip_v << "]"
     << "\n[HL: " << (int)ipheader->ip_hl << "]"
        << "\n[Total Length: " << ipheader->ip_totallength << "]"
     << "\n[ID Num: " << ipheader->ip_id << "]"
     << "\n[TTL: " << (int)ipheader->ip_ttl << "]";
   if (option[3] == 1)
  cout << "\n[********END PACKET********]";
}

void displaytcp(char *packet, char *logfile, int *option)
{
   if (option[4] == 1)
  cout << "\n\n[**********PACKET**********]";
   IPHEADER *ipheader;
   TCPHEADER *tcpheader;
   SOCKADDR_IN srcip, dstip;
   char sourceip[30], destip[30];
   ipheader = (IPHEADER *)packet;
   tcpheader = (TCPHEADER *)(packet + sizeof(IPHEADER));
   srcip.sin_addr.s_addr = ipheader->ip_srcaddr;
   dstip.sin_addr.s_addr = ipheader->ip_destaddr;
   strcpy(sourceip, inet_ntoa(srcip.sin_addr));
   strcpy(destip, inet_ntoa(dstip.sin_addr));
   if (option[4] == 1)
  cout << "\n";
   cout << "\n[--TCP Info--]"
        << "\n[" << sourceip << ":" << tcpheader->sport << " -> " << destip << ":" << tcpheader->dport << "]"
        << "\n[Seq Num: " << tcpheader->seqnum << "]"
        << "\n[Ack Num: " << tcpheader->acknum << "]"
        << "\n[Window Size: " << tcpheader->Windows << "]";
   if (option[7] == 0)
   {
  int totallen = ipheader->ip_totallength;
  int len = ((ntohs(ipheader->ip_totallength))-(sizeof(IPHEADER) + sizeof(TCPHEADER)));
  unsigned char *data = (unsigned char *) packet + sizeof(IPHEADER) + sizeof(TCPHEADER);
  cout << "\n***[DATA]***\n";
  for (int x = 0; x < len; x++)
  {
     if ((*(data+x) >= 20) && (*(data+x) <= 127))
    cout << (char)*(data+x);
     else
    cout << ".";
     if (x%30 == 0)
    cout << "\n";
  }
  cout << "\n***[END DATA]***\n";
   }
   cout << "\n[********END PACKET********]";
}

void displayudp(char *packet, char *logfile, int *option)
{
   if (option[4] == 1)
  cout << "\n\n[**********PACKET**********]";
   IPHEADER *ipheader;
   UDPHEADER *udpheader;
   SOCKADDR_IN srcip, dstip;
   char sourceip[30], destip[30];
   ipheader = (IPHEADER *)packet;
   udpheader = (UDPHEADER *)(packet + sizeof(IPHEADER));
   srcip.sin_addr.s_addr = ipheader->ip_srcaddr;
   dstip.sin_addr.s_addr = ipheader->ip_destaddr;
   strcpy(sourceip, inet_ntoa(srcip.sin_addr));
   strcpy(destip, inet_ntoa(dstip.sin_addr));
   if (option[4] == 1)
  cout << "\n";
   cout << "\n[--UDP Info--]"
        << "\n[" << sourceip << ":" << udpheader->sport << " -> " << destip << ":" << udpheader->dport << "]"
        << "\n[Length: " << udpheader->Length << "]";
   if (option[7] == 0)
   {
  int totallen = ipheader->ip_totallength;
  int len = ((ntohs(ipheader->ip_totallength))-(sizeof(IPHEADER) + sizeof(UDPHEADER)));
  unsigned char *data = (unsigned char *) packet + sizeof(IPHEADER) + sizeof(UDPHEADER);
  cout << "\n***[DATA]***\n";
  for (int x = 0; x < len; x++)
  {
     if ((*(data+x) >= 20) && (*(data+x) <= 127))
    cout << (char)*(data+x);
     else
    cout << ".";
     if (x%30 == 0)
    cout << "\n";
  }
  cout << "\n***[END DATA]***\n";
   }
   cout << "\n[********END PACKET********]";
}

void displayicmp(char *packet, char *logfile, int *option)
{
   if (option[4] == 1)
  cout << "\n\n[**********PACKET**********]";
   IPHEADER *ipheader;
   ICMPHEADER *icmpheader;
   SOCKADDR_IN srcip, dstip;
   char sourceip[30], destip[30];
   ipheader = (IPHEADER *)packet;
   icmpheader = (ICMPHEADER *)(packet + sizeof(IPHEADER));
   srcip.sin_addr.s_addr = ipheader->ip_srcaddr;
   dstip.sin_addr.s_addr = ipheader->ip_destaddr;
   strcpy(sourceip, inet_ntoa(srcip.sin_addr));
   strcpy(destip, inet_ntoa(dstip.sin_addr));
   if (option[4] == 1)
  cout << "\n";
   cout << "\n[--ICMP Info--]"
        << "\n[" << sourceip << ":" << " -> " << destip << "]"
        << "\n[Type: " << (int)icmpheader->icmp_type << "]"
        << "\n[Code: " << (int)icmpheader->icmp_code << "]"
        << "\n[ID Num: " << icmpheader->icmp_id << "]"
        << "\n[Seq Num: " << icmpheader->icmp_seq << "]";
   if (option[7] == 0)
   {
  int totallen = ipheader->ip_totallength;
  int len = ((ntohs(ipheader->ip_totallength))-(sizeof(IPHEADER) + sizeof(ICMPHEADER)));
  unsigned char *data = (unsigned char *) packet + sizeof(IPHEADER) + sizeof(ICMPHEADER);
  cout << "\n***[DATA]***\n";
  for (int x = 0; x < len; x++)
  {
     if ((*(data+x) >= 20) && (*(data+x) <= 127))
    cout << (char)*(data+x);
     else
    cout << ".";
     if (x%30 == 0)
    cout << "\n";
  }
  cout << "\n***[END DATA]***\n";
   }
   cout << "\n[********END PACKET********]";
}


Imp


Last edited by Guest on 31 Dec 2003 11:21:38 am; edited 1 time in total
Back to top
Twiztid33


Member


Joined: 06 Jun 2003
Posts: 106

Posted: 02 Jan 2004 11:39:45 pm    Post subject:

if i still had vb installed i would definently use this program, keep up the good work
Back to top
JoeImp
Enlightened


Active Member


Joined: 24 May 2003
Posts: 747

Posted: 03 Jan 2004 05:38:21 am    Post subject:

Just to clear up the record... thats C++ lol. Use VC++ or some other compiler for it.

Imp
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement