Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pscbot committed Dec 4, 2022
0 parents commit 367fd0c
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# VB6 source files (show diff + keep CRLF in zip download)

*.bas working-tree-encoding=CP1252 text eol=crlf linguist-language=vb6
*.cls working-tree-encoding=CP1252 text eol=crlf linguist-language=vb6
*.ctl working-tree-encoding=CP1252 text eol=crlf linguist-language=vb6
*.dob working-tree-encoding=CP1252 text eol=crlf linguist-language=vb6
*.dsr working-tree-encoding=CP1252 text eol=crlf linguist-language=vb6
*.frm working-tree-encoding=CP1252 text eol=crlf linguist-language=vb6
*.pag working-tree-encoding=CP1252 text eol=crlf linguist-language=vb6
*.vbg working-tree-encoding=CP1252 text eol=crlf
*.vbl working-tree-encoding=CP1252 text eol=crlf
*.vbp working-tree-encoding=CP1252 text eol=crlf
*.vbr working-tree-encoding=CP1252 text eol=crlf
*.vbw working-tree-encoding=CP1252 text eol=crlf

# Other source files (show diff + LF only in zip download)

*.asm text
*.asp text
*.bat text
*.c text
*.cpp text
*.dsp text
*.dsw text
*.h text
*.idl text
*.java text
*.js text
*.manifest text
*.odl text
*.php text
*.php3 text
*.rc text
*.sln text
*.sql text
*.vb text
*.vbs text

# Binary

*.res binary
*.frx binary
*.ctx binary
*.dsx binary
*.exe binary
*.dll binary
*.ocx binary
*.cmp binary
*.pdb binary
*.tlb binary
*.xls binary
*.doc binary
*.ppt binary
*.xlsx binary
*.docx binary
*.pptx binary
*.chm binary
*.hlp binary
*.jpg binary
*.png binary
*.bmp binary
*.gif binary
*.ico binary
*.zip binary
*.cab binary
*.7z binary
*.gz binary

# Text files but keep as binary (no diff)

# *.cfg text
# *.conf text
# *.csi text
# *.css text
# *.csv text
# *.def text
# *.htm text
# *.html text
# *.inf text
# *.ini text
# *.log text
# *.reg text
# *.rtf text
# *.txt text
# *.url text
# *.xml text
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.scc
*.dca
*.oca
*.obj
vb*.tmp
@PSC*
34 changes: 34 additions & 0 deletions GetPublicIP/Project1.vbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Type=Exe
Form=frmGetPublicIP.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\WINDOWS\system32\stdole2.tlb#OLE Automation
Object={248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0; mswinsck.ocx
IconForm="frmGetPublicIP"
Startup="frmGetPublicIP"
Command32=""
Name="Project1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Tiamat Studios"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1
11 changes: 11 additions & 0 deletions GetPublicIP/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Alright, I know there are lots of these but the ones I found dont work so here is a working one.
This uses only winsock to do all its parsing, it sends a packet request to whatismyip.com and saves the html returned. Then it finds where the ip address is located and parses it out. Now it also decodes the ip address since whatismyip seems to have encoded the ip address for what ever reason.
When its done (usually in less then a second) it calls GotPublicIP(IP as string)
inside that sub you can make it do whatever you wanted the internet or public ip address for.
To use simply call GetPublicIP() and place code for what to do with the public IP in GotPublicIP(IP as string)
under this function the variable IP is the public ip address, you can also use the PublicIPAddress variable both contain the same thing.
Hope this helps and enjoy!!
You may use this code in your projects but please give me credit where you can and it would be great if you would link to my website as well. http://tiamat-studios.net

Created by Jordan Barrett aka SPY-3
Website: http://tiamat-studios.net
131 changes: 131 additions & 0 deletions GetPublicIP/frmGetPublicIP.frm
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "mswinsck.ocx"
Begin VB.Form frmGetPublicIP
BackColor = &H00FFFFFF&
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
BackColor = &H00FFFFFF&
Caption = "Connect"
Height = 255
Left = 0
Style = 1 'Graphical
TabIndex = 0
Top = 0
Width = 1215
End
Begin MSWinsockLib.Winsock WS
Left = 0
Top = 240
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
End
Attribute VB_Name = "frmGetPublicIP"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'You may freely use this in your programs, please give me credit wherever you can!
'And a link to my website if you will, http://tiamat-studios.net Thanks and enjoy!
'Created by Jordan Barrett aka SPY-3

Dim HTML As String, PublicIPAddress As String, ArrivalTimes As Integer

Public Sub GetPublicIP()
ArrivalTimes = 0 'We will recieve data twice for the page
HTML = "" 'This will hold the html data returned
WS.Close
DoEvents
WS.Connect "whatismyip.com", 80 'Connect to whatismyip.com
End Sub

Private Sub Command1_Click()
GetPublicIP
End Sub

Private Sub WS_Close()
Dim I As Integer, I1 As Integer
I = InStr(1, HTML, "<h1>Your IP Is", vbTextCompare) + 14 'Find where the ip address begins in the html
I1 = InStr(I, HTML, "</h1>", vbTextCompare) 'Find where the ip address ends in the html header
PublicIPAddress = DecodeIPAddress(Mid(HTML, I, I1 - I)) 'Set this variable to the public ip address
GotPublicIP PublicIPAddress 'Call the sub that tells you when its finished
HTML = "" 'Reset the html so this can be called again later if needed
End Sub

Private Sub WS_Connect()
Dim WebPacket As String
'Simulate a Web Browser Request Packet, I built a basic webserver so I can easily view what
'packets web browsers send to request files, here is a simple one taken from a homepage request.
WebPacket = "GET / HTTP/1.1" & vbCrLf & _
"Host: " & WS.RemoteHost & vbCrLf & _
"Connection: Keep-Alive" & vbCrLf & _
vbCrLf & vbCrLf
'Fairly easy to understand, first the Get /(homepage) HTTP/1.1(html version)
'Host is just the host I connected to, in this case whatismyip.com
'Connection keep alive is as it sounds, tells the server to stay connected to the webbrowser
DoEvents
WS.SendData WebPacket 'Send the packet
End Sub

Private Sub WS_DataArrival(ByVal bytesTotal As Long)
Dim ReturnPacket As String
WS.GetData ReturnPacket 'Get the returned packet which is part 1 of the html
HTML = HTML & ReturnPacket 'add it to the variable
ArrivalTimes = ArrivalTimes + 1 'On the second arrival I have the full html
If ArrivalTimes = 2 Then 'which is what this checks for
ArrivalTimes = 0 'Reset it so it can be used later
WS.Close 'Disconnect since we got what we wanted
WS_Close 'Call the Winsock_Close event so it can parse the ip address
End If
End Sub

Public Function DecodeIPAddress(EncodedIP As String) As String
'After a short time I have figured out what the encoded characters represent
'&#46; = .
'&#48; = 0
'&#49; = 1
'&#50; = 2
'&#51; = 3
'&#52; = 4
'&#53; = 5
'&#54; = 6
'&#55; = 7
'&#56; = 8
'&#57; = 9
'Start
'<h1>Your IP Is
'End
'</h1>
Data = EncodedIP
Data = Replace(Data, "&#46;", ".", , , vbTextCompare)
Data = Replace(Data, "&#48;", "0", , , vbTextCompare)
Data = Replace(Data, "&#49;", "1", , , vbTextCompare)
Data = Replace(Data, "&#50;", "2", , , vbTextCompare)
Data = Replace(Data, "&#51;", "3", , , vbTextCompare)
Data = Replace(Data, "&#52;", "4", , , vbTextCompare)
Data = Replace(Data, "&#53;", "5", , , vbTextCompare)
Data = Replace(Data, "&#54;", "6", , , vbTextCompare)
Data = Replace(Data, "&#55;", "7", , , vbTextCompare)
Data = Replace(Data, "&#56;", "8", , , vbTextCompare)
Data = Replace(Data, "&#57;", "9", , , vbTextCompare)
Data = Replace(Data, "</span>", "", , , vbTextCompare)
Data = Replace(Data, "<span>", "", , , vbTextCompare)
Data = Replace(Data, " ", "", , , vbTextCompare)
'Data = Replace(Data, "", "", , , vbTextCompare)
DecodeIPAddress = Data
End Function

Public Sub GotPublicIP(IP As String)
'You can place anything you want here, if you did a game you would place something to inform
'someone what their internet or public ip address is
MsgBox IP
End Sub

47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<div align="center">

## Get Public Internet IP Address


</div>

### Description

Alright, I know there are lots of these but the ones I found dont work so here is a working one.

This uses only winsock to do all its parsing, it sends a packet request to whatismyip.com and saves the html returned. Then it finds where the ip address is located and parses it out. Now it also decodes the ip address since whatismyip seems to have encoded the ip address for what ever reason.

When its done (usually in less then a second) it calls GotPublicIP(IP as string)

inside that sub you can make it do whatever you wanted the internet or public ip address for.

To use simply call GetPublicIP() and place code for what to do with the public IP in GotPublicIP(IP as string)

under this function the variable IP is the public ip address, you can also use the PublicIPAddress variable both contain the same thing.

Hope this helps and enjoy!!

You may use this code in your projects but please give me credit where you can and it would be great if you would link to my website as well. http://tiamat-studios.net

### More Info



<span> |<span>
--- |---
**Submitted On** |2007-09-24 20:54:10
**By** |[SPY\-3](https://github.com/Planet-Source-Code/PSCIndex/blob/master/ByAuthor/spy-3.md)
**Level** |Intermediate
**User Rating** |4.2 (25 globes from 6 users)
**Compatibility** |VB 5\.0, VB 6\.0
**Category** |[Coding Standards](https://github.com/Planet-Source-Code/PSCIndex/blob/master/ByCategory/coding-standards__1-43.md)
**World** |[Visual Basic](https://github.com/Planet-Source-Code/PSCIndex/blob/master/ByWorld/visual-basic.md)
**Archive File** |[Get\_Public2084589242007\.zip](https://github.com/Planet-Source-Code/spy-3-get-public-internet-ip-address__1-69369/archive/master.zip)








0 comments on commit 367fd0c

Please sign in to comment.