Mega Code Archive

 
Categories / Delphi / Examples
 

Ip packet structure

Title: ip packet structure Question: ip packet structure Mahir DEMR (Nov 19 2001 1:18PM) hi; i want to get the packet in the network.and split that packet get the packet Destination ip, source ip .. this program my project not for hacker or cracker.i am not hacker.i am university student.please help me. I also would like to know this..., if you are not willing to post this information on your website, i was hoping that you em@il the source code..., this would be much apprecaited Answer: if i knew the answer..., i would gladly post it. But..., get this up ya!. function TMain.checkips(address: string): string; var Num, X: Integer; Cpy1: String; begin if chk1.Checked = false then begin Cpy1 := address; X := StrLen(PChar(Cpy1)); if X = 7 then begin Cpy := ''; for Num := 0 to X do begin if Copy(Cpy1, 1, 1) = '1' then begin Cpy := Cpy + '1'; Delete(Cpy1, 1, 1); IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end else if Copy(Cpy1, 1, 1) = '2' then begin Cpy := Cpy + '2'; Delete(Cpy1, 1, 1); IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end else if Copy(Cpy1, 1, 1) = '3' then begin Cpy := Cpy + '3'; Delete(Cpy1, 1, 1); IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end else if Copy(Cpy1, 1, 1) = '4' then begin Cpy := Cpy + '4'; Delete(Cpy1, 1, 1); IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end else if Copy(Cpy1, 1, 1) = '5' then begin Cpy := Cpy + '5'; Delete(Cpy1, 1, 1); IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end else if Copy(Cpy1, 1, 1) = '6' then begin Cpy := Cpy + '6'; Delete(Cpy1, 1, 1); IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end else if Copy(Cpy1, 1, 1) = '7' then begin Cpy := Cpy + '7'; Delete(Cpy1, 1, 1); IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end else if Copy(Cpy1, 1, 1) = '8' then begin Cpy := Cpy + '8'; Delete(Cpy1, 1, 1); IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end else if Copy(Cpy1, 1, 1) = '9' then begin Cpy := Cpy + '9'; Delete(Cpy1, 1, 1); IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end else if Copy(Cpy1, 1, 1) = '0' then begin Cpy := Cpy + '0'; Delete(Cpy1, 1, 1); IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end else if Copy(Cpy1, 1, 1) = '.' then begin Cpy := Cpy + '.'; Delete(Cpy1, 1, 1); if IPCnt = 0 then begin Result := '#005'; Break; end else begin IPCnt := Succ(IPCnt); if StrLen(PChar(Cpy1)) begin Result := Cpy; Break; end end end else begin Result := '#001'; Break; end end end else begin Result := '#002'; end end else begin Result := address; end end; function TMain.checkipex(address: string): string; var X, Y, Z, Num: Integer; Cpy1, Cpy2, Chk: String; begin Cpy1 := Trim(address); Chk := checkips(Cpy1); IPCnt := 0; if Chk = '#001' then begin Result := '#001'; end else if Chk = '#002' then begin Result := '#002'; end else if Chk = '#005' then begin Result := '#005'; end else begin X := StrLen(PChar(Chk)); for Num := 0 to X do begin X := StrLen(PChar(Chk)); if X = 1 then begin Y := Pos('.', Chk); if Y = 3 then begin Cpy2 := Copy(Chk, 1, Y -1); Delete(Chk, 1, Y); Z := StrToInt(Cpy2); if Z = 256 then begin Result := '#003'; Break; end else begin IPCnt := Succ(IPCnt); end end else if Y = 0 then begin Cpy2 := Copy(Chk, 1, X); Delete(Chk, 1, X); Z := StrToInt(Cpy2); if Z = 256 then begin Result := '#003'; Break; end else begin IPCnt := Succ(IPCnt); end end else begin Cpy2 := Copy(Chk, 1, Y -1); Delete(Chk, 1, Y); Z := StrToInt(Cpy2); if Z = 256 then begin Result := '#003'; Break; end else if Z = 0 then begin if IPCnt = 0 then begin Result := '#004'; Break; end end else begin IPCnt := Succ(IPCnt); end end end else begin Result := address; end end end end; checkip results (please do not directly call this procedure, use checkipex instead) : #001 = Invalid character #002 = Invalid ip checkipex results : #001 = Invalid character #002 = Invalid ip #003 = Ip address has a value greater than 255 #004 = Ip address begins with 0 #005 = Ip address begins with . Umm..., sorry if i haven't declared all of the variables in this code (Some may be globally declared). I don't think i can explain it any better than that..., i hope someone finds some use for it, i know i did...