Page 1 of 1 1
Topic Options
#133851 - 2005-02-15 08:00 PM Find out IP, Subnet and MAC address of computer
M_Kiewitz Offline
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
#133852 - 2005-02-15 08:20 PM Re: Find out IP, Subnet and MAC address of computer
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

getting the MAC is impossible in any other way



What about @Address?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#133853 - 2005-02-15 08:27 PM Re: Find out IP, Subnet and MAC address of computer
M_Kiewitz Offline
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 Offline
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 Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#133856 - 2005-02-15 08:54 PM Re: Find out IP, Subnet and MAC address of computer
M_Kiewitz Offline
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 Offline
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
#133858 - 2005-02-16 12:41 AM Re: Find out IP, Subnet and MAC address of computer
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Install WMI on NT to get around the compatibility reasons or get rid of NT at all. COM is bliss.
_________________________
There are two types of vessels, submarines and targets.

Top
#133859 - 2005-02-16 09:42 AM Re: Find out IP, Subnet and MAC address of computer
M_Kiewitz Offline
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
#133860 - 2005-02-16 11:13 AM Re: Find out IP, Subnet and MAC address of computer
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#133861 - 2005-02-16 05:05 PM Re: Find out IP, Subnet and MAC address of computer
M_Kiewitz Offline
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
#133862 - 2005-02-16 05:47 PM Re: Find out IP, Subnet and MAC address of computer
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... you opened this can of worms.

I think it is safe to say that almost everyone hates legacy systems. In some environments it is possible to sequester old unsupported OSes or at least marginalize them. IMHO, any legacy system that cannot be upgraded should (must) be sequestered since it poses a risk to itself and the other systems. We do have legacy NT4 on our process but we island the systems behind a firewall and they do not participate in the mainstream domain. There are even a couple of Wintendos but they are not allowed to connect to any network at all. You will not find an NT4 or Wintendo on my LAN.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#133863 - 2005-02-16 06:26 PM Re: Find out IP, Subnet and MAC address of computer
M_Kiewitz Offline
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
#133864 - 2005-02-16 06:51 PM Re: Find out IP, Subnet and MAC address of computer
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
migrate to linux and get it over then....
Top
#133865 - 2005-02-16 06:55 PM Re: Find out IP, Subnet and MAC address of computer
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

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.




Actually, I have worked in more than one hospital and clinic.

If you think it is just virus threats, then you are myopic, my friend.
We have legacy systems in place that when the hardware fails, our techs have a difficult time to find replacement hardware that will still work with NT4 SP1. Try finding a computer that has video and network drivers that don't need at least SP3.

I'd have to say that it is you that doesn't "have a freakin clue what you are talking about".
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#133866 - 2005-02-16 07:17 PM Re: Find out IP, Subnet and MAC address of computer
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Or when having old legacy systems start to impact the company’s performance.

These old systems take more and more resources to maintain, also finding outdated hardware to replace them, not to mention the time and effort of your tech support team.

Any system that requires pre ntsp3 is a poorly designed system. There is no reason that you should not be able to take your old NT based system to the latest available NT SP just for compatibility issues alone!

And yes go ahead and migrate to a linux based solution, i am curious to see how a linux migration would be cheaper than your current windows legacy system.

You have linux software packages that will replace those windows software packages? No, got a programmer on staff to write them? You prepared for a complete in house programming solution to support a 100% custom linux environment like you are describing? I don’t think you do, because if you did your old legacy programs would not have compatibility problems with today’s xp based systems. If you in-house programming solution is Bob the programmer, when happens when Bob leaves, and the company finds them self in and even worse position than they are now?

Are your tech's really able to support linux at the level needed for a migration like you are taking about to take place, we are not talking about desktop level computers.

Linux is not "free". You pay for IT one way or another.

Top
#133867 - 2005-02-16 07:19 PM Re: Find out IP, Subnet and MAC address of computer
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Gentelmen, this is becoming way off topic. Please take this offline or to another board if you wish to further discuss.

Thank you for your understanding.

Top
#133868 - 2005-02-16 09:33 PM Re: Find out IP, Subnet and MAC address of computer
burnsc Offline
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 Offline
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
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1172 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.079 seconds in which 0.031 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org