获取IP地址并根据IP映射驱动器 [英] get the ip address and map a drive according to IP

查看:98
本文介绍了获取IP地址并根据IP映射驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用ipconfig.exe来获取我的IP地址,

的情况是我需要自动执行此过程。


我需要编写一个DOS程序,它发出一个运行IPCONFIG的命令来获取IP地址,然后发出net use命令来映射

网络上的驱动器。


我知道你可以使用系统


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





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

启动shell,但是如何从捕获IP地址然后从IP中捕获输出?


我可以知道我需要映射的网络上的哪个服务器

到,所以我可以发出另一个


系统(command.com net use z:\\ xyzserver \ myshare mypw / User:me)


来映射驱动器,我还需要检查网络使用是否正常工作。


谢谢!


格雷格

解决方案



gr ****** @ wendys.com 于08/14/06 11:56写道:


我知道我可以使用ipconfig.exe来获取我的IP地址,

的情况是我需要自动执行此过程。


我需要编写一个DOS程序发出运行IPCONFIG的命令到

获取IP地址然后发出net use命令来映射

网络上的驱动器。


我知道你可以使用系统


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





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

启动shell,但是如何捕获它的输出?



这是comp.lang.c中的问题19.30经常

问题(FAQ)列表

http://www.c-faq.com/
< blockquote class =post_quotes>
我捕获IP地址然后从IP我可以知道我需要映射到哪个服务器

,所以我可以发布另一个


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


来映射驱动器,我还需要检查网络使用是否正常工作。



这些是问题19.28和19.29。


-
Er ********* @ sun.com


gr******@wendys.com 写道:


我知道我可以使用ipconfig.exe来获取我的IP地址,

的情况是我需要自动执行这个过程。


我需要编写一个DOS程序,它发出命令运行IPCONFIG

获取IP地址然后发出net use命令来映射

网络上的驱动器。


我知道你可以使用系统


system(''command.com / c ipcoinfig.exe")
< br $> b $ b或


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



你几乎当然不需要显式运行command.com,因为

系统函数使用shell运行指定的命令。 />

system(" ipcoinfig.exe")


另请复制并粘贴实际代码。因为你在

使用了单引号,所以它显然不是你试过的代码。


启动shell,但是如何从中捕获输出?



使用某种特定于系统的方法。在DOS或Windows组中询问

的详细信息。他们可能会告诉你,有一个API可以给你更可靠的信息。


我捕获IP地址后然后从IP我可以知道我需要映射到哪个服务器

,所以我可以发布另一个


系统(" command.com) net use z:\\ xyzserver \ myshare mypw / User:me")


映射驱动器,我还需要检查网络使用是否正常。



与以前相同的评论。另外你需要考虑/字符

在C字符串中有特殊含义所以你可能想要... //用户:我


另外,你确定C程序是合适的吗?这听起来像是一个脚本语言的工作。


我们没有涵盖字符串传递给系统的细节意味着什么

因为它们是特定于系统的。我们也没有涵盖Windows,* nix和其他系统用于网络的API。我们不会覆盖

替代方法来调用外部程序,这些方法可以为您提供更多直接访问程序调用输出的内容。

-

Flash Gordon

在这台电脑上还是没用。


在文章< l6 ****** ******@news.flash-gordon.me.uk>,

Flash Gordon< sp ** @ flash-gordon.me.ukwrote:


> gr ****** @ wendys.com写道:


>系统(command.com net use z:\\ xyzserver \ myshare mypw / User:me)


>与以前相同的评论。另外你需要考虑/字符
在C字符串中有特殊含义所以你可能想要... //用户:我。



是时候更多的caffine,Flash? ;-)

-

当时我还很年轻,但我也很朦胧。

- Christopher Priest


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\myshare mypw /User:me")

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

Thanks!

Greg

解决方案



gr******@wendys.com wrote On 08/14/06 11:56,:

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?

This is Question 19.30 in the comp.lang.c Frequently
Asked Questions (FAQ) list

http://www.c-faq.com/

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\myshare mypw /User:me")

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

These are Questions 19.28 and 19.29.

--
Er*********@sun.com


gr******@wendys.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.

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")

You almost certainly don''t need to explicitly run command.com since the
system function runs the specified command using the shell.

system("ipcoinfig.exe")

Also please copy and paste actual code. Since you used a single quote at
the start it obviously was not the code you had tried.

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

Using some system specific method. Ask in a DOS or Windows group for the
details. They will probably tell you that there is an API that can give
you the information far more reliably.

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\myshare mypw /User:me")

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

Same comments as before. Also you need to consider that the / character
has special meaning in C strings so you probably wanted "... //User:me"

Also, are you sure a C program is the appropriate thing? This sounds to
me more like a job for a scripting language.

We don''t cover the details of what the strings passed to system mean
since they are system specific. We also don''t cover the APIs that
Windows, *nix and other systems have for networking. Not do we cover the
alternative methods of invoking external programs that give you more
direct access to what the program invoked outputs.
--
Flash Gordon
Still sigless on this computer.


In article <l6************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:

>gr******@wendys.com wrote:

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

>Same comments as before. Also you need to consider that the / character
has special meaning in C strings so you probably wanted "... //User:me"

Is it time for more caffine, Flash? ;-)
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest


这篇关于获取IP地址并根据IP映射驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆