Ok.. I am like REALLY new to Visual Basics, but I want to create a program that shows your ip in a window, I just dont know how to do it, I have seen a bunch of pages on it, but none help me, please help me on how, and try to explain what each thing does.. thank you in advanced.
Here's some code to get your IP address.
It's straight out of the AllAPI guide.
Code:
'This project requires the following components:
' - a form (Form1) with a textbox (Text1, Multiline=True)
' and a command button (Command1)
' - a module (Module1)
'in Form1:
Private Sub Command1_Click()
Module1.Start
End Sub
'In Module1:
'******************************************************************
'Created By Verburgh Peter.
' 07-23-2001
' [email protected]
'-------------------------------------
'With this small application , you can detect the IP's installed on your computer,
'including subnet mask , BroadcastAddr..
'
'I've wrote this because i've a programm that uses the winsock control, but,
'if you have multiple ip's installed on your pc , you could get by using the Listen
' method the wrong ip ...
'Because Winsock.Localip => detects the default ip installed on your PC ,
' and in most of the cases it could be the LAN (nic) not the WAN (nic)
'So then you have to use the Bind function ,to bind to your right ip..
'but how do you know & find that ip ?
'you can find it now by this appl.. it check's in the api.. IP Table..
'******************************************************************
Const MAX_IP = 5 'To make a buffer... i dont think you have more than 5 ip on your pc..
Type IPINFO
dwAddr As Long ' IP address
dwIndex As Long ' interface index
dwMask As Long ' subnet mask
dwBCastAddr As Long ' broadcast address
dwReasmSize As Long ' assembly size
unused1 As Integer ' not currently used
unused2 As Integer '; not currently used
End Type
Type MIB_IPADDRTABLE
dEntrys As Long 'number of entries in the table
mIPInfo(MAX_IP) As IPINFO 'array of IP address entries
End Type
Type IP_Array
mBuffer As MIB_IPADDRTABLE
BufferLen As Long
End Type
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As Long, ByVal Sort As Long) As Long
Sub main()
Form1.Show
End Sub
'converts a Long to a string
Public Function ConvertAddressToString(longAddr As Long) As String
Dim myByte(3) As Byte
Dim Cnt As Long
CopyMemory myByte(0), longAddr, 4
For Cnt = 0 To 3
ConvertAddressToString = ConvertAddressToString + CStr(myByte(Cnt)) + "."
Next Cnt
ConvertAddressToString = Left$(ConvertAddressToString, Len(ConvertAddressToString) - 1)
End Function
Public Sub Start()
Dim Ret As Long, Tel As Long
Dim bBytes() As Byte
Dim Listing As MIB_IPADDRTABLE
Form1.Text1 = ""
On Error GoTo END1
GetIpAddrTable ByVal 0&, Ret, True
If Ret <= 0 Then Exit Sub
ReDim bBytes(0 To Ret - 1) As Byte
'retrieve the data
GetIpAddrTable bBytes(0), Ret, False
'Get the first 4 bytes to get the entry's.. ip installed
CopyMemory Listing.dEntrys, bBytes(0), 4
'MsgBox "IP's found : " & Listing.dEntrys => Founded ip installed on your PC..
Form1.Text1 = Listing.dEntrys & " IP addresses found on your PC !!" & vbCrLf
Form1.Text1 = Form1.Text1 & "----------------------------------------" & vbCrLf
For Tel = 0 To Listing.dEntrys - 1
'Copy whole structure to Listing..
' MsgBox bBytes(tel) & "."
CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))
Form1.Text1 = Form1.Text1 & "IP address : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr) & vbCrLf
Form1.Text1 = Form1.Text1 & "IP Subnetmask : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwMask) & vbCrLf
Form1.Text1 = Form1.Text1 & "BroadCast IP address : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwBCastAddr) & vbCrLf
Form1.Text1 = Form1.Text1 & "**************************************" & vbCrLf
Next
'MsgBox ConvertAddressToString(Listing.mIPInfo(1).dwAddr)
Exit Sub
END1:
MsgBox "ERROR"
End Sub
Thank you, that last one helped, though I really dont see what each line did, but when I did it, it tells me the ip, but not my internal ip, only external, how would I get the internal also?
Thank you, that last one helped, though I really dont see what each line did, but when I did it, it tells me the ip, but not my internal ip, only external, how would I get the internal also?
Whaddya mean by internal/extarnal? As in your router/PC?
Yes, I am on a router, I want it to show both.. ok, what i am wanting to create is a program that shows your system information, ip, HD, ram, so forth.. I know its a hard program for a beginner, but it will teach me alot, and be helpful at the same time, but the ip needs to show BOTH ip's.
then with a form with 2 labels, (wanip & lanip) and to textbox's (test1 & text2)
then I added this code: (will give you your local ip and your remote ip)
VB Code:
Option Explicit
Private Const ERROR_SUCCESS As Long = 0
Private Const MAX_ADAPTER_NAME_LENGTH As Long = 256
Private Const MAX_ADAPTER_DESCRIPTION_LENGTH As Long = 128
Private Const MAX_ADAPTER_ADDRESS_LENGTH As Long = 8
Private Type IP_ADDRESS_STRING
IpAddr(0 To 15) As Byte
End Type
Private Type IP_MASK_STRING
IpMask(0 To 15) As Byte
End Type
Private Type IP_ADDR_STRING
dwNext As Long
IpAddress As IP_ADDRESS_STRING
IpMask As IP_MASK_STRING
dwContext As Long
End Type
Private Type IP_ADAPTER_INFO
dwNext As Long
ComboIndex As Long 'reserved
sAdapterName(0 To (MAX_ADAPTER_NAME_LENGTH + 3)) As Byte
sDescription(0 To (MAX_ADAPTER_DESCRIPTION_LENGTH + 3)) As Byte
dwAddressLength As Long
sIPAddress(0 To (MAX_ADAPTER_ADDRESS_LENGTH - 1)) As Byte
dwIndex As Long
uType As Long
uDhcpEnabled As Long
CurrentIpAddress As Long
IpAddressList As IP_ADDR_STRING
GatewayList As IP_ADDR_STRING
DhcpServer As IP_ADDR_STRING
bHaveWins As Long
PrimaryWinsServer As IP_ADDR_STRING
SecondaryWinsServer As IP_ADDR_STRING
LeaseObtained As Long
LeaseExpires As Long
End Type
Private Declare Function GetAdaptersInfo Lib "iphlpapi.dll" _
(pTcpTable As Any, _
pdwSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(dst As Any, _
src As Any, _
ByVal bcount As Long)
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) As Long
Private Declare Function lstrlenW Lib "kernel32" _
(ByVal lpString As Long) As Long
Private Sub Form_Load()
Text1.Text = LocalIPAddress()
Text2.Text = ""
Text2.Text = GetPublicIP()
End Sub
Private Function DownloadFile(ByVal sURL As String, _
Ok, I got the internal ip address or the local ip, but if I am on a router, how do I get around that? I am having major problems lol, thanks for all of the help so far though.
ah I see, then yes simple,
on a form :>projects --> components --> microsoft winsock control
then a command button and textbox with
visual basic code:Private Sub Command1_Click()
Text1.Text = Winsock1.LocalIP
End Sub()
Then penagate wrote:
Quote:
Originally Posted by planethax
visual basic code:End Sub()
Interesting notation...
sorry, couldn't resist
And the funniest part is |2eM!x reply, hehe
Originally Posted by |2eM!x
you have to close the array of end sub, duh!
HAHAHAHAHAH
Originally Posted by penagate
Oh yes, of course
Hey, Moderator: why dont u move this post to the Chit Chat's Jokes Section
Just Playing Around! Anyway, Columbine. First please learn to use Visual Basic and behave like a Programmer and not a Computer User.. plzz .. this is just a request that will help u develop. So, first figure out how to add components Ctrl+T. MORE THAN 3 PPL HAVE EXPLAINED YOU ON HOW TO ADD A CONTROL.
If you get a "Data Member not found error", then u are not using that control you are supposed to use: "Winsock1" or u have a typo in the Method Name.
Please keenly look into the Code or just copy paste it to work. And before that read the posts and add the control properly.
VB Code:
Private Sub Command1_Click()
MsgBox WinSock1.LocalIP
End Sub ' I Aint becoming a joker again here ... hehe
Also, please read everypost from top again. You are just replying to the last post and missed many ppl's code.
Sorry, for any hurts if somehow.
HTH
Neo
Last edited by CodeBlock; May 11th, 2005 at 07:22 AM.