How to get actual local ip address ?
hi
i want to get my actual local ip address, but it's return multiple ip addresses include other network adapters or my internet ip. is there any way to filter result to return only my actual local ip address ?
thanks in advancehttp://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
August 5th, 2011 8:31am
Which OS are you using?
What format do you need to return, or what do you need the ip address for?
Do you need to do it programmatically or is any way to get the info ok?
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 9:09am
if any way is ok, you can execute
netsh interface ip show address name="YourConnectionName"
in your command window where YourConnectionName is for example visible in adapter settings dialog in network and sharing center
August 5th, 2011 9:20am
Which OS are you using?
I'm working on my app in the network (multiple user), so may be win 7, xp or etc. but you can think win 7.
What format do you need to return, or what do you need the ip address for?
the format not important. i want to use this local ip in my app to give users which chat in lan within my app.
Do you need to do it programmatically or is any way to get the info ok?
yes, i want to get this info programmatically, but if i must use cmd or something else, i can do it via my app (don't
worry about)
thanks in advancehttp://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 9:23am
if any way is ok, you can execute
netsh interface ip show address name="YourConnectionName"
in your command window where YourConnectionName is for example visible in adapter settings dialog in network and sharing center
Thanks
but i don't want to use connection name, i want my app get this information automatically.http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
August 5th, 2011 9:27am
Hi Hamed,
This seems more like a programming problem than a technical networking one. Perhaps your question would be better asking the MSDN forum appropriate to your programming language.If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 9:44am
Hi Hamed,
This seems more like a programming problem than a technical networking one. Perhaps your question would be better asking the MSDN forum appropriate to your programming language.
If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
suppose i want to do this without any programming language. i want to do this via my os functionalities.http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
August 5th, 2011 10:36am
The following Powershell script will retrieve your IP address, and store it in a user-level environment variable called IPAddress, that you can access from other programs or the command prompt:
$ip = (Get-WmiObject -class win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"').ipaddress[0]
[Environment]::SetEnvironmentVariable("IPAddress", $ip, "User")
After running this command in Powershell, you can go to a cmd.exe window and type
Set ipaddress <Enter>, and your IP address will be displayed.
If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 11:19am
The following Powershell script will retrieve your IP address, and store it in a user-level environment variable called IPAddress, that you can access from other programs or the command prompt:
$ip = (Get-WmiObject -class win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"').ipaddress[0]
[Environment]::SetEnvironmentVariable("IPAddress", $ip, "User")
After running this command in Powershell, you can go to a cmd.exe window and type
Set ipaddress <Enter>, and your IP address will be displayed.
If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
How can i use powershell ?http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
August 5th, 2011 1:11pm
I assume you are running Windows 7. If so, click the Start (Orb) button, go to All Programs. Under Accessories, you will see a Powershell folder. Open this folder, and click on "Windows Powershell".
If you are not running Windows 7, you can download Powershell, or you could use another method.
If you don't mind my asking, what are you planning to do with this information (the ip address)? This may help us to suggest the best method for your particular needs.If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 1:18pm
I assume you are running Windows 7. If so, click the Start (Orb) button, go to All Programs. Under Accessories, you will see a Powershell folder. Open this folder, and click on "Windows Powershell".
If you are not running Windows 7, you can download Powershell, or you could use another method.
If you don't mind my asking, what are you planning to do with this information (the ip address)? This may help us to suggest the best method for your particular needs.
If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
Thanks for you answer
but when i copy/paste your script in my windows powershell, i'm facing this error :
Unexpected token 'ip' in expression or statement.
At line:1 char:67
+ [Environment]::SetEnvironmentVariable("IPAddress", $ip, "User")$ip <<<< = (Get-WmiObject -class win32_NetworkAdapter
Configuration -Filter 'ipenabled' = "true"').ipaddress[0]
+ CategoryInfo : ParserError: (ip:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
August 5th, 2011 3:57pm
I don't know why, it works on my machine. Try this at your Powershell prompt:
(ipconfig | Select-String "IPv4")[0]
I'll paste that other code again, just in case (this is just to test):
(Get-WmiObject -class win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"').ipaddress[0]
If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 4:05pm
However, none of these solutions take into account that there may be more than one IPv4 address on a machine at one time. Both scripts are just assuming there is only one IPv4 address on the machine.If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
August 5th, 2011 4:11pm
However, none of these solutions take into account that there may be more than one IPv4 address on a machine at one time. Both scripts are just assuming there is only one IPv4 address on the machine.
If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
If so, this is not help me.http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 4:25pm
The following script will get all the IPv4 addresses:
ipconfig | Select-String "IPv4"
If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
August 5th, 2011 4:31pm
The following script will get all the IPv4 addresses:
ipconfig | Select-String "IPv4"
If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
this script works for me, but as u told, it returns multiple resulthttp://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 4:39pm
Hi,
If you do not specify the interface, you cannot get the default interface IP.Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
August 10th, 2011 1:13pm


