说废话的这么多
这问题我前些时候刚解决,解决他起码花了我好多天时间
现给你完整代码
希望马上给我加100分,我是冲着你这100分来的
-----Unit1.pas------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Psock, NMHttp, ExtCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Memo1: TMemo;
Button1: TButton;
NMHTTP1: TNMHTTP;
Timer1: TTimer;
Button2: TButton;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{==================================================================}
procedure TForm1.Button1Click(Sender: TObject);//get网页取源代码
var
i: Integer;
s,s1: string;
begin
try
//----------------------
s:= combobox1.Text;
i:=combobox1.Items.IndexOf(s);
s1:=combobox1.Items.Strings[i+1];
combobox1.Text:=s1;
//----------------------
timer1.Enabled:=false;
NMHTTP1.Get(combobox1.Text);
Memo1.Text := NMHTTP1.Body;
timer1.Enabled:=true;
button2.Click;//过滤取IP
form1.Caption:='myip>>>>'+memo2.Text;
except
form1.Caption:='有问题注意';
timer1.Enabled:=true;
end;
end;
{==================================================================}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
timer1.Interval:=1000*10;
button1.Click; //get网页取源代码
end;
{==================================================================}
function GetIP(src:string):string; //过滤出IP 函数
var i,ipindex:integer;
ip:array [1..4] of string;
begin
result:='';
i:=1;
while i<Length(src) do begin
while (src<='0')or(src>='9') do i:=i+1;
ipindex:=1;
while ipindex<=4 do begin
ip[ipindex]:='';
while (src>='0')and(src<='9') do begin
ip[ipindex]:=ip[ipindex]+src;
i:=i+1;
end;
if (ip[ipindex]='')or(StrToInt(ip[ipindex])>255)or( (ipindex<4)and(src<>'.')) then break
else i:=i+1;
Inc(ipindex);
end;
if ipindex>4 then begin
result:=ip[1]+'.'+ip[2]+'.'+ip[3]+'.'+ip[4];
break;
end;
end;
end;
{==================================================================}
procedure TForm1.Button2Click(Sender: TObject); //过滤出IP
begin
memo2.Text:=GetIp(Memo1.Text);
end;
end.
-------Unit1.dfm-------------
object Form1: TForm1
Left = 253
Top = 129
Width = 431
Height = 330
Caption = 'nmhttp'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ComboBox1: TComboBox
Left = 16
Top = 24
Width = 382
Height = 21
ItemHeight = 13
TabOrder = 0
Text = 'http://www.lk52.com/ip/IPFrom.asp'
Items.Strings = (
'http://ip.loveroot.com/index.php'
'http://www.rich8.com/ip.php'
'http://www.lk52.com/ip/IPFrom.asp')
end
object Memo1: TMemo
Left = 8
Top = 80
Width = 375
Height = 113
TabOrder = 1
end
object Button1: TButton
Left = 72
Top = 48
Width = 98
Height = 25
Caption = 'get'#32593#39029#21462#28304#20195#30721
TabOrder = 2
OnClick = Button1Click
end
object Button2: TButton
Left = 8
Top = 200
Width = 75
Height = 25
Caption = #36807#28388#20986'IP'
TabOrder = 3
OnClick = Button2Click
end
object Memo2: TMemo
Left = 104
Top = 248
Width = 153
Height = 38
TabOrder = 4
end
object NMHTTP1: TNMHTTP
Port = 0
ReportLevel = 0
Body = 'Default.htm'
Header = 'Head.txt'
InputFileMode = False
OutputFileMode = False
ProxyPort = 0
Left = 12
Top = 232
end
object Timer1: TTimer
OnTimer = Timer1Timer
Left = 336
Top = 56
end
end