473,785 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get the ip address and map a drive according to IP

Hi, I know I can use ipconfig.exe is DOS to get my IP address, the
situation is I need to automat this process.

I need to write a DOS program which issue a command to run IPCONFIG to
get the IP address then issue a net use command to map a drive on the
network.

I know you can use system

system ('command.com /c ipcoinfig.exe")

or

system ('command.com ipcoinfig.exe")

the start the shell, but how do I capture the output from it?

after I capture the IP address then from the IP I can know which server
on the network I need to map to, so I can issue another

system("command .com net use z: \\xyzserver\mys hare mypw /User:me")

to map the drive, I need to also check if the net use worked correctly.

Thanks!

Greg

Aug 14 '06
12 3539
On Tue, 15 Aug 2006 12:43:14 +1000, in comp.lang.c , Simon Biber
<ne**@ralmin.cc wrote:
>gr******@wendy s.com wrote:
>Hi, I know I can use ipconfig.exe is DOS to get my IP address, the
situation is I need to automat this process.

No, you can't use ipconfig.exe in DOS. The ipconfig.exe program is a
Win32 console executable:
See, this is why we avoid offtopic answers. To anyone under the age of
around 20, DOS means a Windows command prompt, not your actual DOS...
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Aug 15 '06 #11
>Hi, I know I can use ipconfig.exe is DOS to get my IP address, the
>situation is I need to automat this process.

I need to write a DOS program which issue a command to run IPCONFIG to
get the IP address then issue a net use command to map a drive on the
network.
You say "the IP address" like it was unique. It's not. Most systems
where you even care about IP addresses have at least two (and sometimes
hundreds per network interface), and one of them is 127.0.0.1 .
>I know you can use system

system ('command.com /c ipcoinfig.exe")

or

system ('command.com ipcoinfig.exe")
ipcoinfig.exe is limited to systems with the coin-slot attachment
on the keyboard. This can't compile due to the types of quotes
used above.
>the start the shell, but how do I capture the output from it?
Some shells allow I/O redirection, in a system-dependent manner.
Just about *ANY* command you feed to system() is system-dependent
(exception: a NULL pointer). You may need a trap and suitable bait.

I recommend you hand-type any command you intend passing to system()
to the shell used by system() and verify that it works the way
you expect before proceeding.
>after I capture the IP address
There you go with *the* IP address again. Press CTRL-ALT-DEL with
*THE* finger (hint: it's attached to *MY* hand, not yours, and
it's not long enough to reach from CTRL to DEL).
>then from the IP I can know which server
on the network I need to map to, so I can issue another

system("comman d.com net use z: \\xyzserver\mys hare mypw /User:me")
You probably don't want a literal string here, as you've indicated
that some of the content of this string is dependent on your
IP address information. What is \m inside a string? You probably
need to double up on all the backslashes inside a quoted string literal.
>to map the drive, I need to also check if the net use worked correctly.
Does "net use" return status to the shell, which might be returned
to system() (all together now:) IN A SYSTEM-DEPENDENT MANNER?

Is there a way of testing whether it worked? E.g. try to open
a file you know is supposed to exist, and if it fails, your drive mapping
may have failed.
Aug 15 '06 #12
On 2006-08-15, Mark McIntyre <ma**********@s pamcop.netwrote :
On Tue, 15 Aug 2006 12:43:14 +1000, in comp.lang.c , Simon Biber
<ne**@ralmin.c cwrote:
>>gr******@wend ys.com wrote:
>>Hi, I know I can use ipconfig.exe is DOS to get my IP address, the
situation is I need to automat this process.

No, you can't use ipconfig.exe in DOS. The ipconfig.exe program is a
Win32 console executable:

See, this is why we avoid offtopic answers. To anyone under the age of
around 20, DOS means a Windows command prompt, not your actual DOS...
I detest that comment. I've used DOS for longer than I've used Windows.
I never really learned to like those BSOD's. ;-)

(And I'm under 20.)

--
Andrew Poelstra <http://www.wpsoftware. net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
Aug 16 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6055
by: Mr. Smith | last post by:
Hi All. I need to be able to determine the IP address a drive letter is mapped to. When a user selects a file from a file open dialog, They will, as usual, navigate to the file they want via; Drive letter, folder, folder etc. The Windows file open dialog returns this path in the format C:\folder\folder\file.ext. What I need to know is what is the IP of the C:\ drive or any drive they select, be it P; U; or whatever.
21
1798
by: Stephen Biggs | last post by:
Given this code: void f(void){} int main(void){return (int)f+5;} Is there anything wrong with this in terms of the standards? Is this legal C code? One compiler I'm working with compiles this quietly, even with the most stringent and pedantic ANSI and warning levels, but generates code that only loads the address of "f" and fails to make the addition before returning a value from "main".
27
2251
by: Adam Warner | last post by:
Hi all, In the code snippet below I successfully determine the address of val1:* struct o val1=l_SYM_2B(&a).o; print_aesthetic(&val1); The structure o is heavyweight. I understand (hopefully correctly) that (barring compiler optimisations) C will shallow copy the structure into val1.
0
2500
by: john doe | last post by:
How can I use WMI or a WqlObjectQuery to find the hard drive letter of the physical drive location index. For example the following code will give me the physical drive location: StringCollection propNames = new StringCollection(); ManagementClass driveClass = new ManagementClass("Win32_DiskDrive"); PropertyDataCollection props = driveClass.Properties; foreach (PropertyData driveProperty in props) { propNames.Add(driveProperty.Name);
9
2185
by: Andy B | last post by:
If I bought one of these boxes/OS combos as a postgresql database server, would postgresql be able to make the best use of it with a huge (e.g. 40GB) database? Box: HP ProLiant DL585, with 4 AMD64 CPUs and 64GB of RAM. (other vendor options also exist) OS: SUSE enterprise 8 linux for AMD (links to product info at bottom)
18
5155
by: Joe Lester | last post by:
This thread was renamed. It used to be: "shared_buffers Question". The old thread kind of died out. I'm hoping to get some more direction by rephrasing the problem, along with some extra observations I've recently made. The core of the problem is that Postgres is filling up my hard drive with swap files at the rate of around 3 to 7 GB per week (that's Gigabytes not Megabytes) . At this rate it takes roughly two months to fill up my 40...
0
1082
by: Nasiq Ali | last post by:
I have a logical drive which is mapped to a folder in a remote machine . Due to some secuirity reasons the drive can't be accessed from a C#/C++ program . Do Windows have any API which can be used frm a C# application ,so that if I provide the API with the logical drive name it will give back the physical address of the drive e.g. If I pass Z: then it should return //MyMachine/ABC
10
22650
by: kevinliu23 | last post by:
HI, I am new to Python and wanted to know how to check for the remaining disk space on my Windows machine using Python? I was thinking of using the command line "dir" and trying to extract the output from there. But I'm not sure how to extract command line strings using Python either. Anyway help would be appreciated. :)
17
3219
by: ayush patel | last post by:
Hi all, I have created a windows service that has a file watcher and does some operation after it reads that file. i developed it in my local machine and installed the service on server. i have changed the file path and everythng according to server drives. we all in the office share some network drives in which ppl will keep pasting that file and the service on server has to pick it up. which its not doing. when i paste it in netwrok...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.