生成MAC地址的小工具:

{*------------------------------------------------
生成mac地址
@author
@version 2015.7.2
2015.10.22修改
步长最大长度为256,必须为2的n次方
长度不超过5位数
-------------------------------------------------}
unit frmSaveMac; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, math; type
TSaveMacForm = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
SaveDialog1: TSaveDialog;
SaveButton: TButton;
ExitButton: TButton;
Edit7: TEdit;
Label2: TLabel;
Label3: TLabel;
Edit8: TEdit;
Memo1: TMemo;
GroupBox1: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
btn_clear: TButton;
btn_show: TButton;
Memo2: TMemo;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure ExitButtonClick(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit7KeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
procedure SaveButtonClick(Sender: TObject);
procedure Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure btn_clearClick(Sender: TObject);
procedure btn_showClick(Sender: TObject);
private
{ Private declarations }
procedure CheckIsEmpty;
function CheckStepOrLen: Boolean;
procedure ShowData();
Procedure SaveData();
public
{ Public declarations }
end; var
SaveMacForm: TSaveMacForm; implementation {$R *.dfm}
{*------------------------------------------------
文本框只能输入十六进制数、删除键和回车键
@param
@param
-------------------------------------------------}
procedure TSaveMacForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9', 'A'..'F', 'a'..'f', #8, #13]) then
begin
Key := #0;
Application.MessageBox ('只能输入十六进制的数字!', '提示消息', MB_OK + MB_ICONERROR);
end;
end; procedure TSaveMacForm.ExitButtonClick(Sender: TObject);
begin
Close;
end; {*------------------------------------------------
文本框按键事件
@param
@param
-------------------------------------------------}
procedure TSaveMacForm.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
i,j : integer;
begin
/// 输入最大长度
for i := 0 to self.ComponentCount -1 do begin // 循环每个Edit控件 设置最大长度为2 2015.10.22修改
if self.Components[i] is TEdit then begin
(self.Components[i] as TEdit).MaxLength := 2;
end;
if Sender = Edit7 then Edit7.MaxLength := 3;
if Sender = Edit8 then Edit8.MaxLength := 5; // 长度不超过5位数 2015.10.22修改
end; /// 将光标移到最后
for j := 0 to ComponentCount - 1 do begin
if Components[j] is TEdit then begin
(Components[j] as TEdit).SelStart := Length((Components[j] as TEdit).Text);
end;
end; /// 按回车触发
if key = 13 then
begin
if (sender = Edit1) and (length(Edit1.Text) >= 2) then
Edit2.SetFocus;
if (Sender = Edit2) and (length(Edit2.Text) >= 2) then
Edit3.SetFocus;
if (Sender = Edit3) and (length(Edit3.Text) >= 2) then
Edit4.SetFocus;
if (Sender = Edit4) and (length(Edit4.Text) >= 2) then
Edit5.SetFocus;
if (Sender = Edit5) and (length(Edit5.Text) >= 2) then
Edit6.SetFocus;
if (Sender = Edit6) then
Edit7.SetFocus ;
if (Sender = Edit7) then
Edit8.SetFocus;
end;
ExitButton.Enabled := True;
SaveButton.Enabled := True;
end; {*------------------------------------------------
步长只能输入0到9的数字
@param
@param
-------------------------------------------------}
procedure TSaveMacForm.Edit7KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9', #8]) then
Key := #0;
end; procedure TSaveMacForm.FormCreate(Sender: TObject);
var
j: integer;
C: Double;
begin
SaveButton.Enabled := False;
ExitButton.Enabled := False;
RadioButton1.Checked := True; /// 默认输出格式 memo2.Lines.Add('256以内的2的n次方:');
for J := 1 to 8 do
begin
C := power(2, J); /// 2的I次方
memo2.Lines.Add(FloatToStr(C));
end;
end; procedure TSaveMacForm.CheckIsEmpty;
begin
if (Edit1.Text = '') or (Edit2.Text = '') or (Edit3.Text = '') or (Edit4.Text = '') or (Edit5.Text = '') or (Edit6.Text = '') then
begin
Application.MessageBox('输入框必须是12个16进制的数!', '提示', mb_OK + MB_ICONSTOP);
exit;
end; if (length(Edit1.Text )< 2) or (length(Edit1.Text) < 2) or (length(Edit1.Text )< 2) or (length(Edit1.Text) < 2) or (length(Edit1.Text) < 2) or (length(Edit1.Text) < 2) then
begin
Application.MessageBox('每个输入框必须是2个数字!', '提示', MB_OK + MB_ICONERROR);
exit;
end; if (Edit7.Text = '') then
begin
Application.MessageBox('步长不能为空!', '提示', mb_OK);
Edit7.SetFocus;
exit;
end;
if (Edit8.Text = '') then
begin
Application.MessageBox('长度不能为空!', '提示', mb_OK);
Edit8.SetFocus;
exit;
end;
end; function TSaveMacForm.CheckStepOrLen: Boolean;
var
step, L, code, J : integer;
isnot: Boolean;
C: Extended;
begin
result := False;
if Edit7.Text <> '' then begin // 2015/10/24 增加,之前没判断,若为空时 会出现系统错误
step := StrToInt(Edit7.Text);
L := StrToInt(Edit8.Text);
if step > 256 then
begin
Application.MessageBox('步长最大长度为256,请重新输入!', '提示', mb_OK);
Edit7.SetFocus;
exit;
end;
end; // 判断长度
if L >= 100000 then
begin
Application.MessageBox('长度太长,请重新输入!', '提示', mb_OK);
Edit8.SetFocus;
exit;
end; for J := 1 to 8 do
begin
C := power(2, J); /// 2的I次方
if (step = C) or (step = 1) then
begin
result := True;
end;
end; /// 判断步长是否满足条件
if result = False then
begin
Application.MessageBox('步长只能为2的n次方,请重新输入', '提示消息', mb_OK + MB_ICONERROR);
Edit7.SetFocus;
exit;
end;
end; procedure TSaveMacForm.btn_showClick(Sender: TObject);
begin
ShowData();
end; procedure TSaveMacForm.ShowData;
var
SaveFile: string;
value: Integer;
temp, S: string;
I, M1, M2, M3, M4, M5, M6, J : Integer;
C: Extended;
begin
CheckIsEmpty; // 判断是否为空 if CheckStepOrLen = True then begin
Self.Memo1.Lines.Clear;
M1 := StrToInt('$' + Edit1.Text); /// 直接把edit里的数据变成16进制 (是由十进制To十六进制)
M2 := StrToInt('$' + Edit2.Text);
M3 := StrToInt('$' + Edit3.Text);
M4 := StrToInt('$' + Edit4.Text);
M5 := StrToInt('$' + Edit5.Text);
M6 := StrToInt('$' + Edit6.Text);
if RadioButton1.Checked then
Self.Memo1.Lines.Add(IntToHex(M1, 2) + IntToHex(M2, 2) + IntToHex(M3, 2) + IntToHex(M4, 2) + IntToHex(M5, 2) + IntToHex(M6, 2)); /// 将十六进制To十进制
if RadioButton2.Checked then
Self.Memo1.Lines.Add(IntToHex(M1, 2) + IntToHex(M2, 2) + IntToHex(M3, 2) + ':' + IntToHex(M4, 2) + IntToHex(M5, 2) + IntToHex(M6, 2));
if RadioButton3.Checked then
Self.Memo1.Lines.Add(IntToHex(M1, 2) + '-' + IntToHex(M2, 2) + '-' +IntToHex(M3, 2) + '-' + IntToHex(M4, 2) + '-' + IntToHex(M5, 2) + '-' + IntToHex(M6, 2));
for I := 1 to StrToInt(Edit8.Text) do
begin
temp := '0' ;
if M6 < 16 then /// 小于F,则加个0
begin
M6 := StrToInt('$' + IntToStr(M6));
M6 := StrToInt(temp + IntToHex(m6, 2));
end;
if M5 < 16 then
begin
M5 := StrToInt('$' + IntToStr(M5));
M5 := StrToInt(temp + IntToHex(m5, 2));
end;
if M4 < 16 then
begin
M4 := StrToInt('$' + IntToStr(M4));
M4 := StrToInt(temp + IntToHex(m4, 2));
end;
if M3 < 16 then
begin
M3 := StrToInt('$' + IntToStr(M3));
M3 := StrToInt(temp + IntToHex(m3, 2));
end;
if M2 < 16 then
begin
M2 := StrToInt('$' + IntToStr(M2));
M2 := StrToInt(temp + IntToHex(m2, 2));
end;
if M1 < 16 then
begin
M1 := StrToInt('$' + IntToStr(M1));
M1 := StrToInt(temp + IntToHex(m1, 2));
end;
M6 := M6 + StrToInt(Edit7.Text); /// 加步长
if M6 >= 256 then /// 若大于等于FF则进位
begin
M5 := M5 + 1;
M6 := M6 - 256;
end;
if M5 >= 256 then
begin
M4 := M4 + 1;
M5 := M5 - 256;
end;
if M4 >= 256 then
begin
M3 := M3 + 1;
M4 := M4 - 256;
end;
if M3 >= 256 then
begin
M2 := M2 + 1;
M3 := M3 - 256 ;
end;
if M2 >= 256 then
begin
M1 := M1 + 1;
M2 := M2 - 256;
end;
if M1 >= 256 then
Application.MessageBox('超出范围', '提示消息', mb_OK + MB_ICONERROR);
if RadioButton1.Checked then
Self.Memo1.Lines.Add(IntToHex(M1, 2) + IntToHex(M2, 2) + IntToHex(M3, 2) + IntToHex(M4, 2) + IntToHex(M5, 2) + IntToHex(M6, 2));
if RadioButton2.Checked then
Self.Memo1.Lines.Add(IntToHex(M1, 2) + IntToHex(M2, 2) + IntToHex(M3, 2) + ':' + IntToHex(M4, 2) + IntToHex(M5, 2) + IntToHex(M6, 2));
if RadioButton3.Checked then
Self.Memo1.Lines.Add(IntToHex(M1, 2) + '-' + IntToHex(M2, 2) + '-' +IntToHex(M3, 2) + '-' + IntToHex(M4, 2) + '-' + IntToHex(M5, 2) + '-' + IntToHex(M6, 2));
end;
end;
end; procedure TSaveMacForm.SaveData;
var
SaveFile: string;
begin
if CheckStepOrLen = True then begin
/// 保存
SaveDialog1.Filter := '*.txt|*.txt'; //'txtFile( *.txt)|*.txt'; /// txt格式
SaveDialog1.DefaultExt := '*.txt'; /// 默认格式
SaveDialog1.Title := '保存MAC地址';
if SaveDialog1.Execute then
begin
SaveFile := SaveDialog1.FileName;
Memo1.Lines.SaveToFile(SaveFile); /// 保存memo里数据
end;
end;
end; procedure TSaveMacForm.SaveButtonClick(Sender: TObject);
begin
ShowData();
end; procedure TSaveMacForm.Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
i: integer;
begin
if length(Edit1.Text) >= 2 then
Edit2.SetFocus;
if length(Edit2.Text ) >= 2 then
Edit3.SetFocus;
if length(Edit3.Text ) >= 2 then
Edit4.SetFocus;
if length(Edit4.Text ) >= 2 then
Edit5.SetFocus;
if Length(Edit5.Text ) >= 2 then
Edit6.SetFocus;
(* for i := 0 to ComponentCount - 1 do begin
if Components[i] is TEdit then
if Length((Components[i] as TEdit).Text) >= 2 then
end;*)
end; procedure TSaveMacForm.btn_clearClick(Sender: TObject);
var
i: integer;
begin
for i := 0 to self.ComponentCount -1 do begin
if self.Components[i] is TEdit then begin
(self.Components[i] as TEdit).Text := '';
end;
end;
Edit1.SetFocus;
end; end.

delphi 生成网卡MAC地址的更多相关文章

  1. 修改网卡MAC地址后出现问题:device eth0 does not seem to be present, delaying initialization

    修改网卡MAC地址后出现问题:device eth0 does not seem to be present, delaying initialization   1.修改网卡对应的文件,将配置文件中 ...

  2. 【转载】取得系统中网卡MAC地址的三种方法

    From:http://blog.csdn.net/zhangting1987/article/details/2732135 网卡地址这个概念有点混淆不清.因为实际上有两个地址,mac地址和物理地址 ...

  3. Python 获取 网卡 MAC 地址

    /*********************************************************************** * Python 获取 网卡 MAC 地址 * 说明: ...

  4. Linux 下修改网卡MAC地址

    Linux下修改网卡MAC地址 by:授客 QQ:1033553122 例子:修改网卡接口eth0的mac地址 #停用网卡接口,比如eth0 # ifconfig eth0 down #编辑对应的网卡 ...

  5. 获取CPU序列号、网卡MAC地址、硬盘序列号

    <pre name="code" class="csharp"> using System; using System.Collections; u ...

  6. linux/Centos下查看和修改网卡Mac地址(ifconfig命令)

    本文转载自http://www.169it.com/article/14360294838474691537.html linux/Centos下查看网卡Mac地址,输入命令: #ifconfig - ...

  7. Java/JSP获得客户端网卡MAC地址的三种方法解析

    java/jsp获得客户端(IE)网卡MAC地址的方法大概有三种. 1.通过命令方式,在客户端执行Ipconfig 等等.(java/jsp) 2.通过ActiveX的方法.(jsp) 3.通过向13 ...

  8. 获取客户端网卡MAC地址和IP地址实现JS代码

    获取客户端网卡MAC地址和IP地址实现JS代码 作者: 字体:[增加 减小] 类型:转载   获取客户端的一些信息,如IP和MAC,以结合身份验证,相信很多人都会这样做吧,我们这里用Javascrip ...

  9. Centos下查看和修改网卡Mac地址

    linux/Centos下查看网卡Mac地址,输入命令: #ifconfig -a eth0 Link encap:Ethernet HWaddr 00:e4:56:2E:D8:20 00:e4:56 ...

随机推荐

  1. NandFlash读写

    1.NandFlash分类 根据物理结构上的区别,NandFlash主要分为如下两类:•SLC (Single Level Cell): 单层式存储•MLC (Multi Level Cell): 多 ...

  2. Angularjs-Dirty Checking

    Angularjs实现了数据双向绑定,就像下面这样: <!doctype html> <htnl ng-app> <head> <script src=&qu ...

  3. jQuery实现抖动效果

    //抖动效果 //intShakes:抖动次数:intDistance:抖动左右距离:intDuration:持续时间 jQuery.fn.shake = function (intShakes, i ...

  4. 简洁既是美—用while语句复制数组

    简洁既是美,程序员应尽量尝试编写简洁的表达式,争取用简单的代码来实现更多的功能,当然,这也要看情况了(有时候也得考虑程序运行的时间嘛). 在阅读C++Prime Plus到while语句时有一个讲一个 ...

  5. 使用 Git 管理源代码

    在现代软件开发项目中,要成为一个有效的软件开发人员,我们必须能够与其他项目贡献者并行进行开发.源代码管理(SCM)系统不是什么新思想.为了编写一些能够更快速.简单地开发以后软件项目的软件,已经进行了很 ...

  6. Office2007在安装、卸载过程中出错的解决办法

    Micorsoft office professional plus 2007在安装过程中出错,错误1706 如果在安装OFFICE 2007的 时候,遇到“Microsoft Office 2007 ...

  7. 第 一 百 天上课 PHP TP框架 数据库修改和删除

    修改的三种方式 //造数组的方式修改 public function xiugai1() { $db=D('yonghu'); $attr=array ( 'zhanghao'=>001, // ...

  8. Scrum会议10.20

    Scrum会议   组名称:好好学习 项目名称:记账本 参会成员:林莉(Master)胡丽娜 汪东涵 宫丽君 时间:2016.10.20 已完成内容: 1.理解项目和代码. 2.讨论新功能. 计划完成 ...

  9. snmp switch traffic交换机带宽

    上代码 <?php function getstr1($strall,$str1,$str2,$html_charset='utf-8'){ $i1=mb_strpos($strall,$str ...

  10. iOS 不让自动锁屏

    [UIApplication sharedApplication].idleTimerDisabled=YES;