VBS根据mac网卡地址产生一组数字
作者:刚子 日期:2010-01-24
我想用vbs在每台电脑运行的时候产生一组数字,然后利用这组数字做其他事情。比如用在Randomize上的时候。但是前提是必须保证每台电脑产生的数字不一样。于是我想到mac网卡地址。原理下先获取mac网卡地址,然后转换成10进制。代码比较菜,高手莫笑。
程序代码
程序代码on error resume next
Set mc=GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each mo In mc
If mo.IPEnabled=True Then
mac=replace(mo.MacAddress,":","")
Exit For
End If
Next
aaa=mac
a=len(aaa)
j=0
for i=1 to a
sss=a-i+1
x=mid(aaa,sss,1)
if x="a" or x="A" then
x=10
elseif x="b" or x="B" then
x=11
elseif x="c" or x="C" then
x=12
elseif x="d" or x="D" then
x=13
elseif x="e" or x="E" then
x=14
elseif x="f" or x="F" then
x=15
elseif x="1" then
x=1
elseif x="2" then
x=2
elseif x="3" then
x=3
elseif x="4" then
x=4
elseif x="5" then
x=5
elseif x="6" then
x=6
elseif x="7" then
x=7
elseif x="8" then
x=8
elseif x="9" then
x=9
elseif x="0" then
x=0
end if
j=j+x*16^(i-1)
next
backhex=cstr(j)
msgbox backhex
Set mc=GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each mo In mc
If mo.IPEnabled=True Then
mac=replace(mo.MacAddress,":","")
Exit For
End If
Next
aaa=mac
a=len(aaa)
j=0
for i=1 to a
sss=a-i+1
x=mid(aaa,sss,1)
if x="a" or x="A" then
x=10
elseif x="b" or x="B" then
x=11
elseif x="c" or x="C" then
x=12
elseif x="d" or x="D" then
x=13
elseif x="e" or x="E" then
x=14
elseif x="f" or x="F" then
x=15
elseif x="1" then
x=1
elseif x="2" then
x=2
elseif x="3" then
x=3
elseif x="4" then
x=4
elseif x="5" then
x=5
elseif x="6" then
x=6
elseif x="7" then
x=7
elseif x="8" then
x=8
elseif x="9" then
x=9
elseif x="0" then
x=0
end if
j=j+x*16^(i-1)
next
backhex=cstr(j)
msgbox backhex
评论: 0 | 引用: 0 | 查看次数: -
发表评论
上一篇
下一篇

文章来自:
Tags: