Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Volume Control Behavior
Easy Animation
DiskJockey CD-ROM Builder
Stub Projector
simINET Xtra
Play and cleanup DV Sprites
cXtraWindowsConf
Director 7 Demystified
Learning Lingo : The Art and Science of Programming With Macromedia Director
Change the LineSize of a Shape Sprite
 

 

 

Behavior How to find the computer's IP Address at runtime

Added on 6/12/2006

 

Compatibilities:
D8 D8_5 D9 PC Script

Required Xtras:
Buddy API

This item has not yet been rated

Author: MikeBlaustein

This handler will find the IP Address and other related information from the Windows registry. It should work on all versions of Windows from Win95 through XP. It requires the Buddy API xtra.

--This requires BudAPI
--Script written by Mike Blaustein 2003
--Just make this a #movie script in your cast

--If you call getIP(), you get a property list with 4 objects
--It will look something like this:
-- [#Address: "192.168.0.111", #DHCP: "Yes", #Subnet: "255.255.255.0", #Gateway: "192.168.0.100"]

--If you call getIP().Address, you will get a string containing the IP
--If you call getIP().DHCP, you will get an integer -> 1 for true, 0 for false
--If you call getIP().Subnet,you will get a string containing the Subnet Mask
--If you call getIP().Gateway,you will get a string containing the Default Gateway

on getIP me
  
  IPAddress=[#Address:"Error",#DHCP:"Error",#Subnet:"Error",#Gateway:"Error"]
  
  if baVersion("nt")>0 then --this bit is for NT based OSes
    
    bb=baRegKeyList( "SYSTEMControlSet001Services", "HKEY_LOCAL_MACHINE" )
    
    repeat with m=1 to bb.count --find the keys that start with {
      if getat(bb,m) contains "{" then
        secretCode= getat(bb,m)
        --      put "sc="&secretcode
        
        --make sure we have the right one that starts with {
        cc=baRegKeyList( "SYSTEMControlSet001Services"&secretCode&"Parameters", "HKEY_LOCAL_MACHINE" )
        if cc<>[] then --if it is not blank, then it must be the right one
          realCode=secretCode
          --        put "rc="&RealCode
        end if
        
      end if
    end repeat
    
    EnableDHCP = baReadRegNumber( "SYSTEMControlSet001Services"&realCode&"ParametersTcpip", "EnableDHCP", 0, "HKEY_LOCAL_MACHINE" )
    
    if EnableDHCP=1 then --DHCP
      IP = baReadRegString( "SYSTEMControlSet001Services"&realCode&"ParametersTcpip", "DhcpIPAddress", "Error", "HKEY_LOCAL_MACHINE" )
      Subnet=baReadRegString( "SYSTEMControlSet001Services"&realCode&"ParametersTcpip", "DhcpSubnetMask", "Error", "HKEY_LOCAL_MACHINE" )    
      Gateway=baReadRegString( "SYSTEMControlSet001Services"&realCode&"ParametersTcpip", "DhcpDefaultGateway", "Error", "HKEY_LOCAL_MACHINE" )    
      
    else --static
      IP = baReadRegString( "SYSTEMControlSet001Services"&realCode&"ParametersTcpip", "IPAddress", "Error", "HKEY_LOCAL_MACHINE" )    
      Subnet=baReadRegString( "SYSTEMControlSet001Services"&realCode&"ParametersTcpip", "SubnetMask", "Error", "HKEY_LOCAL_MACHINE" )    
      Gateway=baReadRegString( "SYSTEMControlSet001Services"&realCode&"ParametersTcpip", "DefaultGateway", "Error", "HKEY_LOCAL_MACHINE" )    
      
    end if
  else --this bit is for Win9x
    
    --assume it is static
    enableDHCP=0
    
    AdapterList=baRegKeyList( "SystemCurrentControlSetServicesClassNetTrans", "HKEY_LOCAL_MACHINE" )
    repeat with x=1 to AdapterList.count --whichever adapter is PPP is 0.0.0.0 can be safely ignored
      if baReadRegString( "SystemCurrentControlSetServicesClassNetTrans"&getAt(AdapterList,x), "IPAddress", "Error", "HKEY_LOCAL_MACHINE" )="0.0.0.0" then    
        --do nothing
      else
        NetAdapter=getAt(AdapterList,x)      
      end if  
    end repeat
    IP=baReadRegString( "SystemCurrentControlSetServicesClassNetTrans"&NetAdapter, "IPAddress", "Error", "HKEY_LOCAL_MACHINE" )
    Subnet=baReadRegString( "SystemCurrentControlSetServicesClassNetTrans"&NetAdapter, "IPMask", "Error", "HKEY_LOCAL_MACHINE" )
    Gateway=baReadRegString( "SystemCurrentControlSetServicesClassNetTrans"&NetAdapter, "DefaultGateway", "Error", "HKEY_LOCAL_MACHINE" )
    
    --if it isnt static, then we just wasted a bunch of time
    
    if IP="Error" then -- it must be DHCP
      --DHCP
      enableDHCP=1
      
      --Egads! It is in hex in the registry!
      testIP = baReadRegBinary( "SystemCurrentControlSetServicesVxDDHCPDhcpInfo00", "DhcpIPAddress", "error", "HKEY_LOCAL_MACHINE" )
      IP=getAt(testIP,1)&"."&getAt(testIP,2)&"."&getAt(testIP,3)&"."&getAt(testIP,4)
      
      testSubnet=baReadRegBinary( "SystemCurrentControlSetServicesVxDDHCPDhcpInfo00", "DhcpSubnetMask", "error", "HKEY_LOCAL_MACHINE" )
      Subnet=getAt(testSubnet,1)&"."&getAt(testSubnet,2)&"."&getAt(testSubnet,3)&"."&getAt(testSubnet,4)
      
      testGateway=baReadRegBinary( "SystemCurrentControlSetServicesVxDDHCPDhcpInfo00", "DhcpServer", "error", "HKEY_LOCAL_MACHINE" )
      Gateway=getAt(testGateway,1)&"."&getAt(testGateway,2)&"."&getAt(testGateway,3)&"."&getAt(testGateway,4)
    end if --/DHCP
  end if --/OS
  
  IPAddress.address=IP
  IPAddress.subnet=Subnet
  IPAddress.gateway=Gateway
  
  if enableDHCP=1 then
    IPAddress.DHCP="Yes"
  else
    IPAddress.DHCP="No"
  end if
  
  return IPAddress
  
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail