本人delphi 菜鸟 请把步骤尽可能列详细些
12 个解决方案
#1
winexec 执行 ipconfig/all > abc.txt
然后打开abc.txt提取
然后打开abc.txt提取
#2
没有简单一点的办法吗
如果没有能不能提供一下源代码
#3
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Sockets, ExtCtrls;
type
TForm1 = class(TForm)
UdpSocket1: TUdpSocket;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
self.Caption:=self.UdpSocket1.LocalHostName;
self.Caption:=self.Caption+':'+self.UdpSocket1.LocalHostAddr;
end;
end.
#4
网上很多,何不自己动手搜一下
#5
这个方法我见过 什么地方可以找到 UdpSocke 这个控件
#6
这个方法我见过 什么地方可以找到 UdpSocke 这个控件
#7
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
mstr: string;
ss: TStringList;
i: integer;
begin
WinExec('cmd /c ipconfig/all >d:\abc.txt',SW_HIDE);
sleep(1000);
ss := TStringList.Create;
ss.LoadFromFile('d:\abc.txt');
for i:=0 to ss.Count -1 do
begin
mstr := Trim(ss.Strings[i]);
if Pos('Host Name',mstr)>0 then
begin
Delete(mstr,1,Pos(':',mstr)+1);
showmessage('hostname:' + mstr);
end;
if Pos('IP Address',mstr)>0 then
begin
Delete(mstr,1,Pos(':',mstr)+1);
showmessage('ipaddr:' + mstr);
end;
end;
ss.Destroy;
DeleteFile('d:\abc.txt');
end;
end.
#8
谢谢, 很好的方法 就是要考虑不同的操作系统
#9
#10
procedure TForm1.Button3Click(Sender: TObject);
var
namea: array[0..MAX_PATH] of Char;
size: Cardinal;
begin
GetComputerName(namea, size);
ShowMessage(namea);
end;
获取本机IP我没有太好的方法..
var
namea: array[0..MAX_PATH] of Char;
size: Cardinal;
begin
GetComputerName(namea, size);
ShowMessage(namea);
end;
获取本机IP我没有太好的方法..
#11
楼主: 这个应该适合D5,从原来的大富翁论坛找到的,很久很久前的代码。
uses Winsock;
...
function getIP(DNS_hostname: string): string;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
WSAStartup(2, WSAData);
HostEnt := gethostbyname(PChar(DNS_hostname));
with HostEnt^ do
Result := Format('%d.%d.%d.%d', [Byte(h_addr^[0]),
Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
WSACleanup;
end;
#12
发现7楼的方法更通用
#1
winexec 执行 ipconfig/all > abc.txt
然后打开abc.txt提取
然后打开abc.txt提取
#2
没有简单一点的办法吗
如果没有能不能提供一下源代码
#3
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Sockets, ExtCtrls;
type
TForm1 = class(TForm)
UdpSocket1: TUdpSocket;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
self.Caption:=self.UdpSocket1.LocalHostName;
self.Caption:=self.Caption+':'+self.UdpSocket1.LocalHostAddr;
end;
end.
#4
网上很多,何不自己动手搜一下
#5
这个方法我见过 什么地方可以找到 UdpSocke 这个控件
#6
这个方法我见过 什么地方可以找到 UdpSocke 这个控件
#7
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
mstr: string;
ss: TStringList;
i: integer;
begin
WinExec('cmd /c ipconfig/all >d:\abc.txt',SW_HIDE);
sleep(1000);
ss := TStringList.Create;
ss.LoadFromFile('d:\abc.txt');
for i:=0 to ss.Count -1 do
begin
mstr := Trim(ss.Strings[i]);
if Pos('Host Name',mstr)>0 then
begin
Delete(mstr,1,Pos(':',mstr)+1);
showmessage('hostname:' + mstr);
end;
if Pos('IP Address',mstr)>0 then
begin
Delete(mstr,1,Pos(':',mstr)+1);
showmessage('ipaddr:' + mstr);
end;
end;
ss.Destroy;
DeleteFile('d:\abc.txt');
end;
end.
#8
谢谢, 很好的方法 就是要考虑不同的操作系统
#9
#10
procedure TForm1.Button3Click(Sender: TObject);
var
namea: array[0..MAX_PATH] of Char;
size: Cardinal;
begin
GetComputerName(namea, size);
ShowMessage(namea);
end;
获取本机IP我没有太好的方法..
var
namea: array[0..MAX_PATH] of Char;
size: Cardinal;
begin
GetComputerName(namea, size);
ShowMessage(namea);
end;
获取本机IP我没有太好的方法..
#11
楼主: 这个应该适合D5,从原来的大富翁论坛找到的,很久很久前的代码。
uses Winsock;
...
function getIP(DNS_hostname: string): string;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
WSAStartup(2, WSAData);
HostEnt := gethostbyname(PChar(DNS_hostname));
with HostEnt^ do
Result := Format('%d.%d.%d.%d', [Byte(h_addr^[0]),
Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
WSACleanup;
end;
#12
发现7楼的方法更通用