|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
数据库有很多应用领域,但是如果你单单学数据库的话基本上做数据库管理员比较合适而已,跟领域结合的你还得再学习那些领域知识。(其实数据挖掘我真是不懂,本来这学期开了一门课了。监控|流量|收集以下的代码的原作是opensource的一个叫sniffer.net的,用vb.net写的,这里只是复杂的用c#翻译了一下,临时还只能监控一切数据包,不克不及监控某一个历程的数据包,代码以下:
usingSystem;
usingSystem.Text;
usingSystem.Net;
usingSystem.Net.Sockets;
usingSystem.Runtime.InteropServices;namespaceUpdateTester
{
/**////<summary>
///Monitor的择要申明。
///</summary>
publicclassMonitor
{
publicdelegatevoidNewPacketEventHandler(Monitorm,Packetp);
publiceventNewPacketEventHandlerNewPacket;
privateSocketm_Monitor;
privateIPAddressm_Ip;
privatebyte[]m_Buffer=newbyte[65535];
privateconstSystem.Int32IOC_VENDOR=0x18000000;
privateconstintIOC_IN=-2147483648;
privateconstintSIO_RCVALL=IOC_IN^IOC_VENDOR^1;
privateconstintSECURITY_BUILTIN_DOMAIN_RID=0x20;
privateconstintDOMAIN_ALIAS_RID_ADMINS=0x220;
publicSystem.Net.IPAddressIP
{
get{returnm_Ip;}
}
publicbyte[]Buffer
{
get{returnm_Buffer;}
}
publicMonitor()
{
//
//TODO:在此处增加机关函数逻辑
//
}
publicMonitor(IPAddressIpAddress)
{
if(!(Environment.OSVersion.Platform==PlatformID.Win32NT)&&Environment.OSVersion.Version.Major<5)
{
thrownewNotSupportedException("ThisprogramrequiresWindows2000,WindowsXPorWindows.NETServer!");
}
m_Ip=IpAddress;
}
publicvoidStart()
{
if(m_Monitor==null)
{
try
{
m_Monitor=newSocket(AddressFamily.InterNetwork,SocketType.Raw,ProtocolType.IP);
m_Monitor.Bind(newIPEndPoint(IP,0));
m_Monitor.IOControl(SIO_RCVALL,BitConverter.GetBytes(1),null);
m_Monitor.BeginReceive(m_Buffer,0,m_Buffer.Length,SocketFlags.None,newAsyncCallback(OnReceive),null);
}
catch(Exceptione)
{
m_Monitor=null;
thrownewSocketException();
}
}
}
publicvoidStop()
{
if(m_Monitor!=null)
{
m_Monitor.Close();
}
m_Monitor=null;
}
publicvoidOnReceive(System.IAsyncResultar)
{
try
{
intreceived=m_Monitor.EndReceive(ar);
try
{
if(m_Monitor!=null)
{
byte[]pkt=newbyte[received];
Array.Copy(Buffer,0,pkt,0,received);
OnNewPacket(newPacket(pkt,DateTime.Now));
}
}
catch(Exceptione)
{
throw;
}
m_Monitor.BeginReceive(Buffer,0,Buffer.Length,SocketFlags.None,newAsyncCallback(OnReceive),null);
}
catch(Exceptione)
{
}
}
protectedvoidOnNewPacket(Packetp)
{
NewPacket(this,p);
}
}
}
usingSystem;
usingSystem.Text;
usingSystem.Net;
usingSystem.Net.Sockets;
namespaceUpdateTester
{
publicenumPrecedence
{
Routine=0,
Priority=1,
Immediate=2,
Flash=3,
FlashOverride=4,
CRITICECP=5,
InternetworkControl=6,
NetworkControl=7
}
publicenumDelay
{
NormalDelay=0,
LowDelay=1
}
publicenumThroughput
{
NormalThroughput=0,
HighThroughput=1
}
publicenumReliability
{
NormalReliability=0,
HighReliability=1
}
publicenumProtocol
{
Ggp=3,
Icmp=1,
Idp=22,
Igmp=2,
IP=4,
ND=77,
Pup=12,
Tcp=6,
Udp=17,
Other=-1
}
/**////<summary>
///Packet的择要申明。
///</summary>
publicclassPacket
{
privatebyte[]m_Raw;
privateDateTimem_Time;
privateintm_Version;
privateintm_HeaderLength;
privatePrecedencem_Precedence;
privateDelaym_Delay;
privateThroughputm_Throughput;
privateReliabilitym_Reliability;
privateintm_TotalLength;
privateintm_Identification;
privateintm_TimeToLive;
privateProtocolm_Protocol;
privatebyte[]m_Checksum;
privatestringm_SourceAddress;
privatestringm_DestinationAddress;
privateintm_SourcePort;
privateintm_DestinationPort;
publicPacket()
{
//
//TODO:在此处增加机关函数逻辑
//
}
//
//publicPacket(byte[]raw):(byte[]raw,DateTimetime)
//{
//Packet(raw,DateTime.Now);
//}
publicPacket(byte[]raw,DateTimetime)
{
if(raw==null)
{
thrownewArgumentNullException();
}
if(raw.Length<20)
{
thrownewArgumentException();
}
this.m_Raw=raw;
this.m_Time=time;
this.m_HeaderLength=(raw[0]&0xF)*4;
if((raw[0]&0xF)<5){thrownewArgumentException();}
this.m_Precedence=(Precedence)((raw[1]&0xE0)>>5);
this.m_Delay=(Delay)((raw[1]&0x10)>>4);
this.m_Throughput=(Throughput)((raw[1]&0x8)>>3);
this.m_Reliability=(Reliability)((raw[1]&0x4)>>2);
this.m_TotalLength=raw[2]*256+raw[3];
if(!(this.m_TotalLength==raw.Length)){thrownewArgumentException();}//invalidsizeofpacket;
this.m_Identification=raw[4]*256+raw[5];
this.m_TimeToLive=raw[8];
m_Protocol=(Protocol)raw[9];
m_Checksum=newbyte[2];
m_Checksum[0]=raw[11];
m_Checksum[1]=raw[10];
try
{
m_SourceAddress=GetIPAddress(raw,12);
m_DestinationAddress=GetIPAddress(raw,16);
}
catch(Exceptione)
{
throw;
}
if(m_Protocol==Protocol.Tcp||m_Protocol==Protocol.Udp)
{
m_SourcePort=raw[m_HeaderLength]*256+raw[m_HeaderLength+1];
m_DestinationPort=raw[m_HeaderLength+2]*256+raw[m_HeaderLength+3];
}
else
{
m_SourcePort=-1;
m_DestinationPort=-1;
}
}
publicstringGetIPAddress(byte[]bArray,intnStart)
{
byte[]tmp=newbyte[4];
if(bArray.Length>nStart+2)
{
tmp[0]=bArray[nStart];
tmp[1]=bArray[nStart+1];
tmp[2]=bArray[nStart+2];
tmp[3]=bArray[nStart+3];
}
returntmp[0]+"."+tmp[1]+"."+tmp[2]+"."+tmp[3];
}
publicintTotalLength
{
get{returnm_TotalLength;}
}
publicDateTimeTime
{
get{returnthis.m_Time;}
}
publicProtocolProtocol
{
get{returnthis.m_Protocol;}
}
publicstringSourceAddress
{
get{returnthis.m_SourceAddress;}
}
publicstringSource
{
get
{
if(m_SourcePort!=-1)
{
returnSourceAddress.ToString()+":"+m_SourcePort.ToString();
}
else
{
returnSourceAddress.ToString();
}
}
}
publicstringDestination
{
get
{
if(this.m_DestinationPort!=-1)
{
returnDestinationAddress.ToString()+":"+m_DestinationPort.ToString();
}
else
{
returnDestinationAddress.ToString();
}
}
}
publicstringDestinationAddress
{
get
{
returnm_DestinationAddress;
}
}
}
}
在主程序里
privateMonitor[]m_PacketMonitors;
privateArrayListm_Packets;
privateSystem.Windows.Forms.StatusBarstatusBar1;
privateintm_PacketsSize;
实行办法中
privatevoidStartMonitor()
{
IPAddress[]hosts=Dns.Resolve(Dns.GetHostName()).AddressList;
if(hosts.Length==0){thrownewNotSupportedException("Thiscomputerdoesnothavenon-loopbackinterfacesinstalled!");}
for(inti=0;i<hosts.Length;i++)
{
}
m_PacketMonitors=newMonitor[1];
m_Packets=newArrayList();
m_PacketMonitors[0]=newMonitor(hosts[0]);
//增加代办署理,每次有新的packet到时都动身上面哪一个举措
m_PacketMonitors[0].NewPacket+=newMonitor.NewPacketEventHandler(this.OnNewPacket);
m_PacketMonitors[0].Start();
}
//这个办法用于把packet显现到一个中央
privatevoidOnNewPacket(Monitorm,Packetp)
{
m_Packets.Add(p);
m_PacketsSize+=p.TotalLength;
try
{
txtLog.Text+=p.Time.ToString()+p.Protocol.ToString()+p.Source.ToString()+p.Destination.ToString()+p.TotalLength.ToString();
}
catch(Exceptione)
{
MessageBox.Show(e.Message);
}
statusBar1.Text=String.Format("Intercepted{0}packet(s)[{1}bytes]",m_Packets.Count,m_PacketsSize);
}
以前学了大概半年时间的asp(没有机会做大系统,最多是自己对公司系统做些调整和修改还有一些小程序)。应该说开始接触asp.net是今年元月5号的事。现在很想把公司的系统重新用.net来架构,却不知道如何下手。 |
|