|
-
Jan 18th, 2008, 03:20 AM
#1
Thread Starter
Member
Geting client ip address
i have managed to run the asp file in the local network however it add only my ip each time the users run the file
how can i change the code so that i get the user's ip address not mine
i guess it has something to do with the host.
Code:
<%@ Page Language="VB"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
' Declared outside the subs so both can access it.
Dim objConnection As OleDbConnection
Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
Dim value As String = h.AddressList.GetValue(0).ToString()
Dim ipfull As String = h.AddressList.GetValue(0).ToString
Dim ipsplit() As String = ipfull.Split(".".ToCharArray())
'IP.Text = h.AddressList.GetValue(0).ToString()
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
' Set up our connection.
objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("ip.mdb") & ";")
' Every call to the page adds a new record and
' shows the data in the table.
AddNewRecord()
'ShowDataGrid()
End Sub
Sub AddNewRecord()
Dim objCommand As OleDbCommand
Dim strSQLQuery As String
' Our insert command
strSQLQuery = "INSERT INTO ip " _
& "(pcname, username, mip) " _
& "VALUES (@TextValue, @TextValue2, @TextValue3)"
' Create new command object passing it our SQL insert
' and telling it which connection to use.
objCommand = New OleDbCommand(strSQLQuery, objConnection)
' Add parameters that our SQL command takes:
objCommand.Parameters.Add(New OleDbParameter("@TextValue", OleDbType.VarChar, 255))
objCommand.Parameters.Add(New OleDbParameter("@TextValue2", OleDbType.VarChar, 255))
objCommand.Parameters.Add(New OleDbParameter("@TextValue3", OleDbType.VarChar, 255))
objCommand.Parameters("@TextValue").Value = System.Environment.MachineName
objCommand.Parameters("@TextValue2").Value = System.Environment.UserName
objCommand.Parameters("@TextValue3").Value = ipsplit(3)
' Open the connection, execute the command, and close the connection.
Try
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()
status.Text = "data added"
Catch ex As Exception
status.Text = "you can add data only once"
End Try
End Sub
</script>
<html>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Status"></asp:Label>
<asp:TextBox ID="status" runat="server" Width="352px"></asp:TextBox><!-- Plain old DataGrid... format it as you like. -->
</form>
</body>
</html>
-
Jan 18th, 2008, 04:19 AM
#2
Re: Geting client ip address
Use Request.ServerVariables("REMOTE_ADDR"), you're using classes that work with the address of the web server.
-
Jan 18th, 2008, 04:27 AM
#3
Thread Starter
Member
Re: Geting client ip address
how can i make it to get their own ips? n where to place the code
-
Jan 18th, 2008, 06:30 AM
#4
Re: Geting client ip address
You'd replace it on this line
Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
And I don't understand your first question, because this does get their remote address.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|