#133851 - 2005-02-15 08:00 PM
Find out IP, Subnet and MAC address of computer
|
M_Kiewitz
Fresh Scripter
Registered: 2005-02-15
Posts: 15
|
Here goes another code of mine. It uses ipconfig /all for getting the information. That was done because getting the MAC is impossible in any other way (but with a helper EXE file). Also it works on all Windows platforms (NT/2k/XP tested).
Note that you will need to adjust the script for other languages. It's currently working on english and german environments.
FUNCTION GETNETWORKINFORMATION () SHELL "%COMSPEC% /C %WINDIR%\system32\ipconfig.exe /all >%temp%\ipconfig.txt" IF OPEN(10, "%TEMP%\ipconfig.txt")=0 $NetworkLine = READLINE(10) $NetworkInGroup = "NO" WHILE @ERROR=0 IF LEFT($NetworkLine,1)=CHR(9) OR LEFT($NetworkLine,1)=CHR(32) ; Tab/Space-Found, are we already in a group? IF $NetworkInGroup="NO" $NETWORK_IP = "" $NETWORK_SUBNET = "" $NETWORK_MAC = "" $NetworkInGroup = "YES" ENDIF $NetworkLine = SUBSTR($NetworkLine,2) $NetworkPos = INSTRREV($NetworkLine,":") $NetworkData = TRIM(SUBSTR($NetworkLine,$NetworkPos+1)) $NetworkPos = INSTR($NetworkLine,".") IF $NetworkPos>0 $NetworkLine = TRIM(LEFT($NetworkLine,$NetworkPos-1)) IF $NetworkLine="Physikalische Adresse" OR $NetworkLine="Physical Address" $NETWORK_MAC = $NetworkData ENDIF IF $NetworkLine="IP-Adresse" OR $NetworkLine="IP Address" $NETWORK_IP = $NetworkData ENDIF IF $NetworkLine="Subnetzmaske" OR $NetworkLine="Subnet Mask" $NETWORK_SUBNET = $NetworkData ENDIF ENDIF ELSE IF $NetworkInGroup="YES" IF LEN($NETWORK_IP)>0 AND LEN($NETWORK_SUBNET)>0 AND LEN($NETWORK_MAC)>0 $ = CLOSE(10) RETURN ENDIF ENDIF ENDIF $NetworkLine = READLINE(10) LOOP $ = CLOSE(10) ENDIF $NETWORK_IP = "" $NETWORK_SUBNET = "" $NETWORK_MAC = "" ENDFUNCTION
|
|
Top
|
|
|
|
#133853 - 2005-02-15 08:27 PM
Re: Find out IP, Subnet and MAC address of computer
|
M_Kiewitz
Fresh Scripter
Registered: 2005-02-15
Posts: 15
|
Quote:
Quote:
getting the MAC is impossible in any other way
What about @Address?
Okay, I overlooked that. Anyway what about having 2 network adapter. My code is easily enhanceable to match a specific subnet or even check network adapter names.
|
|
Top
|
|
|
|
#133854 - 2005-02-15 08:30 PM
Re: Find out IP, Subnet and MAC address of computer
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
What about the UDF forum which has many IP based UDFs already?
And a sorted mirror
http://www.kixhelp.com/udfs/
or
http://www.gwspikval.com/jooel/UDF/
Thanks for the code, don't want to discourage posting, but might save yourself some time if you review the UDFs first.
Also, when posting please place your code within the [CODE] tags to preserve the formatting.
Edited by NTDOC (2005-02-15 08:31 PM)
|
|
Top
|
|
|
|
#133855 - 2005-02-15 08:40 PM
Re: Find out IP, Subnet and MAC address of computer
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
I know you can do a lot with code.. But wouldn't NBTSTAT cover this?
Kent
|
|
Top
|
|
|
|
#133856 - 2005-02-15 08:54 PM
Re: Find out IP, Subnet and MAC address of computer
|
M_Kiewitz
Fresh Scripter
Registered: 2005-02-15
Posts: 15
|
Quote:
What about the UDF forum which has many IP based UDFs already?
I checked (anyway that's kinda hard because no search function on those sites) and I was only able to find a "GetMAC" function that uses COM again. And I don't use COM, because of compatibility reasons.
Anyway, sorry for posting code.
|
|
Top
|
|
|
|
#133857 - 2005-02-15 09:08 PM
Re: Find out IP, Subnet and MAC address of computer
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
Both sites have a search function. Not sure what search you're looking for.
Quote:
Anyway, sorry for posting code
There is no need to be sorry. I'm not attacking you, I was hopefully pointing out what you may not have known. You are a newly signed on member, so I have no idea how long you've been coding, or how long you been using this board.
Why does everyone always take the position of feeling threatened when ever someone offers advice?
Edited by NTDOC (2005-02-15 09:15 PM)
|
|
Top
|
|
|
|
#133859 - 2005-02-16 09:42 AM
Re: Find out IP, Subnet and MAC address of computer
|
M_Kiewitz
Fresh Scripter
Registered: 2005-02-15
Posts: 15
|
Quote:
Install WMI on NT to get around the compatibility reasons or get rid of NT at all. COM is bliss.
Wrong answer. Zero points.
I'm working at a hospital and we even got some NT SP-3 machines somewhere on mission-critical. Those are not to be updated in any way! We even got some Win9x (not many!) machines here for special hardware that isn't supported on WNT/W2k/WXP. Also we don't have money to spend on updates that are actually unnecessary by just checking what we are doing in our login-script and/or executeables.
Also if you want to get a real bliss, check out REXX. That's a really perfectly designed language and easily enhanceable. I would really like to have some its features in KiX like e.g. enable DLL enhancements by other coders.
Quote:
There is no need to be sorry. I'm not attacking you, I was hopefully pointing out what you may not have known. You are a newly signed on member, so I have no idea how long you've been coding, or how long you been using this board.
So I misunderstood your quote. Sorry. Anyway just fyi: I'm developing under KiX for around 1 1/2 years (at that time I started working here) and migrated our whole login-script to KiX. Runs pretty well here. It also communicates with REXX code running on an OS/2 machine that is also containing our computer-database, software-deployment, CGIs and much more stuff. That's all REXX (including some KiX for software deployment). I started coding under REXX around 5 years ago. I'm also developing under Watcom C/IBM C and I even did some REXX extension DLL. I don't like coding under Win32 platform, especially because our applications NEED to run under various Windows OS and sometimes that can get pretty complicated if you know what I mean.
Edited by M_Kiewitz (2005-02-16 09:50 AM)
|
|
Top
|
|
|
|
#133861 - 2005-02-16 05:05 PM
Re: Find out IP, Subnet and MAC address of computer
|
M_Kiewitz
Fresh Scripter
Registered: 2005-02-15
Posts: 15
|
Quote:
damn... didn't bother reading the whole thread but your last post only. I hope to see you joining in the small group that keeps knocking on ruuds shoulder about the enchangements that are vital. at least your bacground says you might have something to say what comes to best practise opinions etc.
Actually it's the other way round. I got reasons to do what I'm doing. In some of my REXX DLL extensions I'm even using assembly code. So what? That's MY choice. I don't complain about someone doing things differently, but I don't like people complaining about not using some w31rd M$-library that isn't supported on all the required (for me!) platforms. You know how much CLINICAL software costs? So telling me to "upgrade" is just non-sense. If it works, why change it. Because of a function-call in a login-script? Are you kidding me? Some people probably have too much money, well we do not. We don't throw it out like crazy madmen.
Also just get a clue and take a look at REXX. You would be astonished on how advanced it is in comparsion to e.g. KiX or VBS. REXX was designed centuries ago for IBM/390 mainframes. I have to admit: KiX *is* the way to go under Windows (instead of VBS), but it's not the best scripting language ever (no offense intended).
|
|
Top
|
|
|
|
#133863 - 2005-02-16 06:26 PM
Re: Find out IP, Subnet and MAC address of computer
|
M_Kiewitz
Fresh Scripter
Registered: 2005-02-15
Posts: 15
|
Quote:
Well... you opened this can of worms.
I think it is safe to say that almost everyone hates legacy systems.
You ever worked at a hospital? No, you didn't? Oh that's sad. So you dont have a freakin clue what you are talking about.
Quote:
legacy system that cannot be upgraded should (must) be sequestered since it poses a risk to itself and the other systems.
A risk? What risk? We had not a single virus in the last 4 years (!) here - and that's because of good firewalls, policy & e-mail/surf filtering and not because we apply every single M$ patch to our systems. I upgraded some old EKG-system (ONE computer!) some months ago. The company asked 6000EUR for doing it. I did it in around 3-4 days for "free". This time was needed because of COMPATIBILITY issues that come up on EVERY new M$ operating system. And I changed the system because the old systems hardware slowly broke, not because of a software problem. This whole hospital (including some retirement homes) are administed by exactly 3 (THREE) people. Updating every single computer here with all the special software including fixing M$ bugs would be a waste of time and money.
BTW. We still got around 70 P2(233) systems here (AND THEY WORK), most new systems get W2k. Wxp is a big no-no here, especially because of all sorts of compatibilty issues and a broken GUI. If this continues we will migrate to Linux and that's it.
|
|
Top
|
|
|
|
#133868 - 2005-02-16 09:33 PM
Re: Find out IP, Subnet and MAC address of computer
|
burnsc
Starting to like KiXtart
Registered: 2004-04-14
Posts: 171
|
Basicly you only have a few ways to get this data.
1) shell out to a program/script that returns the data to the script. Where this program comes from(downloaded, programmed by you, purchased) would only be relevant to your companys policy on such programs. I wrote a program a few years ago that read the MAC address from a NIC, though I did not have multiple NIC compatibility, it also did not have 'return' capabilities that you would need.
2) Find an internal function in kix that provides this ability.
What 'technologies' these methods support depends the requirements of the product you use to make it to your end goal. Like it or not COM is here, and it makes MANY things simpler, but it is not always required; however, more and more programs are useing it. Also more and more programs that dont use it are moveing out of the marketplace. This leaves you with 1 generally available choice. Custom development. This can be done by you or someone that you find.
Everyone here is right about the situations that occur in IT and are justified in their assesment due to this. I work in IT, so I see much of this as well.
Most companies need the support of external market level products to maintain certain company standards(for various reasons). Due to this those companies are also directly tied to upgradeing to maintain the product requirements of these programs.
Moderators,
Please indulge this post. My primary intent is to give the very basic options available to the poster. If I went too far off topic in this responce please accept my apologies.
Edited by burnsc (2005-02-16 09:38 PM)
|
|
Top
|
|
|
|
#133869 - 2005-02-17 12:37 AM
Re: Find out IP, Subnet and MAC address of computer
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
How can I get a clue? 
Anyway, regarding the retrieval of MAC addresses: For Windows 9x MAC addresses are recorded on a per-adapter basis in the following registry location: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\Net For Windows NT/2000/XP/2003 MAC Addresses are recorded in: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\Net HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\Net\000<x>\ NetworkAddress HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\<One Big number>\<One Little Number>\NetworkAddress
You might need to search the registry for additional locations using 'NetworkAddress' as the search term.
Thus, they can all be retrieved via (remote) registry access. The same holds true for the other NIC-related info you're trying to retrieve as I've already demonstrated in the EnumIPInfoAll() UDF.
And just so you know, I've worked in a German hospital in the mid 90s using state-of-the-art Windows 3.11 workstation computers connected to a Novell network. That was about the same time I was programming multiple single-board computers to interact with each other using Motorola 68040 processors, serial cables, and Assembler. I've also worked in biomedical research using "mission-critical" VAX VMS computers running ancient Fortran code used to analyze electrical signals recorded via probes from within muscle spindles.
However, I can only comment on available information. Your inital information was not detailed enough, so I had to assume a standard work environment with reasonably up-to-date computers, thus the comment regarding the installation of WMI in order to simplify certain administrative tasks is permissible. Other than that, the other Moderators have already said what I'd say as well
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 1172 anonymous users online.
|
|
|